excel - issues with Run time error 9 on vba code -


i need debugging weird bug found on 1 of workbooks. wrote vba code excel file , somehow calling different workbook. ill give example lets have excel file called "test1", file has references workbook called "test2" following code applies workbook "test1"

   lastrow = cells(rows.count, 1).end(xlup).row ' last row    msgbox (lastrow) 'wrote debugging purposes    worksheets("salescontest").range("a3:a" & lastrow).clear 

i have code can clear contents row in "test1" file problem comes when randomly open "test2" , somehow runs code above on "test2" though suppose run on "test1" when open "test2" there messagebox says number of rows in "test2" , gives me following error message "run time error 9" subscript out of range" there way can fix doesnt call "test2" "test1"

you can use thisworkbook.worksheets("salescontest").range("a3:a" & lastrow).clear make sure it's applying workbook code running.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -