I've been working through some of the ideas in How To Avoid Using Select in Excel VBA Macros. I have 3 sheets in my test workbook and want to move the cursor to a specific cell on each sheet after other actions have been carried out. The following enters the cell value but only moves the activecell to M5 on the initial sheet:
Dim rngTest As Range
Dim shtTest As Worksheet
Set rngTest = [M5]
For Each shtTest In ThisWorkbook.Sheets
With shtTest
.Range("m10").Value = "hello"
End With
rngTest.Select
Next shtTest
Where as this does what I want (enters the cell value then move to M5 on each sheet):
Dim rngTest As Range
Dim shtTest As Worksheet
Set rngTest = [M5]
For Each shtTest In ThisWorkbook.Sheets
With shtTest
.Range("m10").Value = "hello"
End With
[M5].Select
Next shtTest
In the top sample I tried making each sheet active first before moving to rngTest but that created the 1004 error.
So, why does [M5].select work whereas rngTest.Select fails?