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

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -