I have a values in column C of stuff1, stuff2 and on down.
I have a value in cell A1.
I want to start in C1, and every Nth, where N is the value in cell A1, select and paste into column H.
My problem is that the selected cells don't start in C1, in fact, based on the value in A1, it starts in different cells in column C. AND, if i press the button twice, the returned values are different.
Private Sub CommandButton1_Click()
'Sub SelectEveryNthCell()
Dim rRange As Range
Dim rEveryNth As Range
Dim lRow As Long
With Sheet1
Set rRange = .Range("C1", .Cells(.Rows.Count, "C").End(xlUp))
End With
For lRow = 1 To rRange.Rows.Count Step Range("a1").Value
If lRow = 1 Then
Set rEveryNth = rRange(lRow, 1)
Else
Set rEveryNth = Union(rRange(lRow, 1), rEveryNth)
End If
Next lRow
Application.Goto rEveryNth
Selection.Copy
ActiveSheet.Range("j1").Select
Selection.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=False
End Sub
Link to source code
i've attached a sample.
Bookmarks