excel vba - Copy and Paste to next available column -
i'm trying track weekly quantities have in spread sheet. far i've made macro copy , paste info need it. paste spot chose while recording macro. i'd paste info next available column.
i'd schedule macro run once week on friday morning.
macro i'm using now.
sub copypaste() ' ' copypaste macro ' ' range("g4:g33").select selection.copy range("b35").select selection.pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _ :=false, transpose:=false end sub
i've tried putting & lastrow range, gets compile error. appreciated.
you can work out column number of last column this:
sub copypaste() ' ' copypaste macro ' dim lastcol long ' finds number of last column lastcol = cells(35, columns.count).end(xltoleft).column range("g4:g33").copy ' range("b35").select ' no need select. paste cell in row 35, 1 right of last column cells(35, lastcol + 1).pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _ :=false, transpose:=false end sub
you add 1 right in lastcol definition, like
lastcol = cells(35, columns.count).end(xltoleft).column + 1 range("g4:g33").copy cells(35, lastcol).pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _ :=false, transpose:=false
Comments
Post a Comment