vba - Copy row to a new sheet - button macro -


i wanting move selected row of data new sheet when button pressed. have below code working, overwrites existing row above last row in destination sheet, insert new row in destination sheet. in advance

sub move_row()  'declare variables    dim sht1 worksheet    dim sht2 worksheet    dim sht3 worksheet    dim lastrow long  'set variables   set sht1 = sheets("incremental opps") set sht2 = sheets("forecast data")  'select entire row  selection.entirerow.select  'move row destination sheet & delete source row lastrow = sht2.range("a" & sht2.rows.count).end(xlup).row  selection  .copy destination:=sht2.range("a" & lastrow - 1) .entirerow.delete    end  end sub 

try without new line

sub move_row()     activecell.entirerow.copy worksheets("forecast data").range("a" & worksheets("forecast data").range("a" & rows.count).end(xlup).row - 1)     activecell.entirerow.delete end sub 

with new line (insert)

sub move_row()     worksheets("forecast data").range("a" & worksheets("forecast data").range("a" & rows.count).end(xlup).row).insert shift:=xldown     activecell.entirerow.copy worksheets("forecast data").range("a" & worksheets("forecast data").range("a" & rows.count).end(xlup).row - 1)     activecell.entirerow.delete end sub 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -