0

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

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.