I have just found something that seems strange to me. If I resize a range the address of that range does not get resized at the same time. This then prevents being able to step through the range using a For Each loop.
Question: do I really have to SET the range so that I can loop through it?
Question: do I really have to SET the range so that I can loop through it?
Code:
Sub TestSub()
Dim rTarget As Range
Dim Cell As Range
Set rTarget = Range("A1")
rTarget.Resize(5, 5) = 1
Debug.Print rTarget.Address 'this produces $A$1
Set rTarget = Range("A1:E5")
Debug.Print rTarget.Address '$A$1:$E$5
'if you comment out the previous two lines
'there is only one pass through this bit of code instead of 5
For Each Cell In rTarget.Columns(5).Rows
Cell = Cell * 5
Next
End Sub
Last edited: