W
Webtechie
I have programmed many routines in which I need to dynamically select a range.
However, lately, I am getting an error message when selection a range.
Sub myCode()
dim lRow as long
dim lCol as long
dim wks as worksheet
dim wb as workbook
dim myRng as range
set wb = thisworkbook
set wks = wb.sheets("recordset")
lRow = wks.range("a1").end(xlDown).row
lCol = wks.range("a1").end(xlToRight).column
set myRng = wks.range(cells(1,1), cells(lRow, lCol))
Sometimes the above statement is causing a error
"Run time error '1004'"
Method 'Range' of object '_Worksheet' failed
I am using Excel XP.
Can anybody makes sense of this and why I get this error sometimes?
Thanks.
However, lately, I am getting an error message when selection a range.
Sub myCode()
dim lRow as long
dim lCol as long
dim wks as worksheet
dim wb as workbook
dim myRng as range
set wb = thisworkbook
set wks = wb.sheets("recordset")
lRow = wks.range("a1").end(xlDown).row
lCol = wks.range("a1").end(xlToRight).column
set myRng = wks.range(cells(1,1), cells(lRow, lCol))
Sometimes the above statement is causing a error
"Run time error '1004'"
Method 'Range' of object '_Worksheet' failed
I am using Excel XP.
Can anybody makes sense of this and why I get this error sometimes?
Thanks.