Excel color cell by level of indent


I am seeking to color cells in a column by the level of indent. Would you be able to shoot me in the right direction to accomplish this?

Thank you, in-advance!
John DarbyPMAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
I'd need to see the workbook.
Martin LissOlder than dirtCommented:
Or at least a workbook that contains a sheet with "indented" data.
John DarbyPMAuthor Commented:
Thank you,

Here is the column I am seeking to add color per level of indent
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Martin LissOlder than dirtCommented:
No attachment.
John DarbyPMAuthor Commented:
Trying again :)
Martin LissOlder than dirtCommented:
Okay do you want to use coloring similar to the black and gray you have now?
John DarbyPMAuthor Commented:
That would be great...I am mostly not wanbting to present a bunch of saturated colors which shock consumers :)

Thank you!
Martin LissOlder than dirtCommented:
Try this macro.

Sub ColorByIndentLevel()
Dim lngLastRow As Long
Dim lngRow As Long
lngLastRow = Range("B1048576").End(xlUp).Row

For lngRow = 3 To lngLastRow ' To start with row 1, change the 3 to a 1)
    If Cells(lngRow, 2).Text <> "" Then
        With Cells(lngRow, 2)
            ' Other than black (RGB(0,0,0)), the bigger the number (up to 255
            ' which is white) the lighter the shade of gray
            Select Case .IndentLevel
                Case 0
                    .Interior.Color = RGB(0, 0, 0)
                    .Font.Color = vbWhite
                Case 1
                    .Interior.Color = RGB(128, 128, 128)
                Case 2
                    .Interior.Color = RGB(169, 169, 169)
                Case 3
                    .Interior.Color = RGB(211, 211, 211)
                Case 4
                    .Interior.Color = RGB(220, 220, 220)
                Case Else
            End Select
        End With
    End If

End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
John DarbyPMAuthor Commented:
Thanks Martin,

silly me...how do you "apply" the macro? I have it in the VB Explorer, inserted into the editor
check this file

you can set the cells for level color templates to be used
Martin LissOlder than dirtCommented:
silly me...how do you "apply" the macro? I have it in the VB Explorer, inserted into the editor
Open Excel
Choose Insert->Module from the menu
Copy my code to the module

If you want to assign a Shortcut Key
Go back to the sheet view
Select the Developer tab
Select Macros from the menu
Select the macro
Click Options...
John DarbyPMAuthor Commented:
Thanks FarWest!


thank you! I ran the Debug and it executed the instructions against the page...thanks again!
John DarbyPMAuthor Commented:
Thank you!
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
John DarbyPMAuthor Commented:
Thanks Marty!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.