excel - VBA Copy & Paste only selecting 2 cells based on active sheet -


i'm getting strange error code whereby if don't have sheet soh active before running macro copy cells b1 & b2 other workbook template build.

i've attached workings below.

public sub info_copy()    dim lastrow integer    dim soh excel.workbook    set soh = workbooks("stockoh")    dim template excel.workbook    set template = workbooks("template build")  lastrow = activesheet.cells(rows.count, 1).end(xlup).row   soh.sheets("nsf").activate range("b2:b" & lastrow).copy template.sheets("sheet1").activate     range("b2").select     activesheet.paste 

you counting number of rows on active sheet because used activesheet object.

if don't want use active sheet each time need tell exactly sheet use. example:

lastrow = workbooks("someworkbook").worksheets("somesheet").cells(rows.count, 1).end(xlup).row 

it's difficult tell, guess need this

lastrow = soh.worksheets("soh").cells(rows.count, 1).end(xlup).row 

Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -