• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Looping

sandeepkumar4u

New Member
Hello All,

I am new to Excel VBA programming so this might look like a dumb question to most of you. I have 2 columns, one has numbers and other has some text. I would like to indent text based on the numbers in first column. I wrote follwing

Code:
Sub P_4410()
Dim i As Integer
For i = 2 To 2472
    If Cells(i, 1).Value = 2 Then
        Cells(i, 2).InsertIndent 1
    ElseIf Cells(i, 1).Value = 3 Then
        Cells(i, 2).InsertIndent 2
    ElseIf Cells(i, 1).Value = 4 Then
        Cells(i, 2).InsertIndent 3
    End If
Next i
End Sub

This works fine but I would like to loop it instead of putting i=2472. The reason is that I have other similar sheet and the row count can be anything and Instead of writing a row number I would like to loop it so that it stops by itself.

Any help?

EDITED (SirJB7, Luke M)
 
Appreciate the feedback, but in the same vein, I'd request using code tags whenever you post codes. It enhances readability.

FYI Sam, if you write "code=vb" instead of just "code" (replace the quotation marks with square brackets) you can improve readability. It's not listed as one of the supported languages when you click the code button, but works just fine. Check out the above posts (edited to show VB). :D
 
Back
Top