Reputation: 315
I have a for each loop, how can I incrementally increase my cells output by one column? Currently this just writes to one cell in output.
Sub quarterly()
Dim result As String
rev = Sheets("fin").Range("B105:F105")
For Each x In rev:
result = Replace(x, "M", "")
Sheets("output").Cells(2, 2) = result
Next
End Sub
Upvotes: 0
Views: 477
Reputation: 13386
if your "target" range is empty then you could use End(xlToLeft)
and step one cell right at any cell writing :
Sub quarterly()
Dim x, rev
rev = Sheets("fin").Range("B105:F105").Value
With Sheets("output")
For Each x In rev
.Cells(2, .Columns.Count).End(xlToLeft).Offset(, 1) = Replace(x, "M", "")
Next
End With
End Sub
Upvotes: 1
Reputation: 152465
You can use a counter:
Sub quarterly()
dim j as long
j = 0
dim rev as range
rev = workSheets("fin").Range("B105:F105")
dim x as variant
For Each x In rev
Dim result As String
result = Replace(x, "M", "")
Sheets("output").Cells(2, 2+j) = result
j=j+1
Next
End Sub
Upvotes: 3