Share via

Insert Indent in Excel 2010 Using VBA

Anonymous
2014-08-27T16:29:33+00:00

I need to indent a column in a spreadsheet up to 2500 rows and would like to automate the indenting process. The number of 'indents' is in another column. I want to indent the name column the number in the Outline_Level -1. I appreciate any help.

Here is the before:

Outline_Level Name
1 ECLSS - CLIN 1: DDTE/Certification
2 Start/Completion Dates
3 Advanced Design Development
3 CCtCAP Work
2 Program Management Dashboard
3 ETA Block 0.5
4 ETA Block 0.5 Start

Here is the after:

Outline_Level Name
1 ECLSS - CLIN 1: DDTE/Certification
2 Start/Completion Dates
3 Advanced Design Development
3 CCtCAP Work
2 Program Management Dashboard
3 ETA Block 0.5
4 ETA Block 0.5 Start
Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2014-08-27T20:56:09+00:00

Select all the data (not including the header row) and run the following:

Sub AddIndents()

    Dim i As Long

    Dim theRange As Range

'

' Application.ScreenUpdating = False ' Optional

    Set theRange = Selection

'

    For i = 1 To theRange.Rows.Count

        theRange.IndentLevel = 0

        theRange.Cells(i, 2).InsertIndent theRange.Cells(i, 1)

    Next i

' Application.ScreenUpdating = True ' Optional

'

End Sub

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2014-08-28T18:06:11+00:00

    That's what happens when you hand-type something - oops!

    Glad it helped.

    Eric

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-08-28T15:06:34+00:00

    Thank you E.J. You saved me a LOT of time.

    I did move the line 'theRangeIndetLevel = 0' to above the For Next loop.

    Over 8000 rows in nothing flat.

    Stretch

    Was this answer helpful?

    0 comments No comments