In loops, I always prefer to use the Cells class using the R1C1 reference method, for example:
Cells(rr, col).Formula = ...
This allows me to cycle quickly and easily in a range of cells:
Dim r As Long Dim c As Long c = GetTargetColumn() ' Or you could just set this manually, like: c = 1 With Sheet1 ' <-- You should always qualify a range with a sheet! For r = 1 To 10 ' Or 1 To (Ubound(MyListOfStuff) + 1) ' Here we're looping over all the cells in rows 1 to 10, in Column "c" .Cells(r, c).Value = MyListOfStuff(r) '---- or ---- '...to easily copy from one place to another (even with an offset of rows and columns) .Cells(r, c).Value = Sheet2.Cells(r + 3, 17).Value Next r End With
LimaNightHawk Aug 20 '15 at 16:50 2015-08-20 16:50
source share