Cut - Paste an auto-detected range in Excel VBA -


i trying cut , paste chunks of cells, auto-detected line range, in defined position (specifically, right after last used cell in column or b).

sub cut_range_to_clipboard()  'detecting number of used lines in chunck of code need cut dim lastrow long     activesheet         lastrow = .cells(.rows.count, "t").end(xlup).row         msgbox lastrow     end  'detecting number of used lines in column need paste code   dim lastrow2 long     activesheet         lastrow2 = .cells(.rows.count, "b").end(xlup).row         msgbox lastrow2     end  'cells(20, 3) = t3  range(cells(20, 3), cells(36, lastrow)).cut range(cells(2, lastrow2 + 1)).select activesheet.paste  range("t1").cut range(cells(1, lastrow2 + 1)).select activesheet.paste  columns("t:ak").entirecolumn.delete end sub 

when executing code, line range(cells(2, lastrow2 + 1)).select outputs error 1004, , cannot understand why.

you need add address property of cells (necessary whenever call range 1 cell argument). so:

range(cells(2, lastrow2 + 1).address).select 

while fix problem, there many changes should make in code, including avoiding select, improve performance , avoid other issues


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -