I’d like to write some VBA that performs an action repeatedly on cells until it reaches the worksheet edge, eg column A, no matter where it started from. I’ve found that if I tell it to repeat more times than there are columns I get an error as the code tries to move to a column to the left of column A. How can I limit a loop to stop at column A?
For example, if I use
For n = 1 To 5
'
ActiveCell.Offset(0, -1).Range("A1:A2").Select
Selection.merge
'
Next n
Then if I start this with a cell in column G selected it’s OK, but if I had a cell in column F or less selected, it crashes.
Thanks!
This should do what you want. Note that a key principal of VBA is that there’s almost never a need to
Selectcells. (Although the macro recorder doesn’t know that).