PDA

View Full Version : Simple Loop For Selecting a Range and Replacing Values



marcusaj
01-28-2019, 03:43 PM
Hey Y'all,

So this is probably pretty easy to do but I'm just not sure how. I'm trying to create a loop that populates a range with values that go in order of the same column +10 rows at a time.

For example:
In range O2:O10 I'd like the values of A2, A12, A22, and so on. So O2 would have the value of A2, O3 would have the value of A12, O4 would have the value of A22.... You get the idea.

Thanks in advance for the help!!!

Paul_Hossler
01-28-2019, 04:58 PM
Option Explicit

'In range O2:O10 I'd like the values of A2, A12, A22, and so on.
'So O2 would have the value of A2, O3 would have the value of A12, O4 would have the value of A22

Sub test()
Dim i As Long

With ActiveSheet
For i = 2 To 10
.Cells(i, 15).Value = .Cells(10 * i - 18, 1).Value ' 15 = Col O, 1 = Col A
Next i
End With
End Sub

marcusaj
01-28-2019, 06:40 PM
Option Explicit

'In range O2:O10 I'd like the values of A2, A12, A22, and so on.
'So O2 would have the value of A2, O3 would have the value of A12, O4 would have the value of A22

Sub test()
Dim i As Long

With ActiveSheet
For i = 2 To 10
.Cells(i, 15).Value = .Cells(10 * i - 18, 1).Value ' 15 = Col O, 1 = Col A
Next i
End With
End Sub




Thanks!!!