I have this code and it is working fine if I run the macro while Sheet1 is selected or activated.
However it fails when other sheets are selected. Why?
I get a:
Runtime Error: Select method of range class failed
Isn't it covered when I Set ws = ThisWorkbook.Sheets("Sheet1")
Sub test()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A1:M" & lrow).Select
End With
End Sub
How can I improve the code and avoid the Runtime Error
?
What am I missing?
Any help would be much appreciated.