Auto-indent based on the value of another column?

ridug

New Member
Joined
Mar 16, 2023
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hey all,

I have a CSV sitemap that I'm formatting and one of the requests is to indent the Page Name column "X" amount of times based on the value of another column. The other column contains the "Level", which is simply a number between 1 and 6, and based on that is the number of indents the Page Name should receive. E.g.:
1678979691185.png
- 2=1 indent, 3=2 indents, etc..

Is there a way for me to speed this process up semi/fully automatically? Would greatly appreciate any input :)

Thank you!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Having 1 for no indent makes no sense to me. If it were zero then something like this should work (I just used a loop from 1 to 9 with 9 rows as a test, in col's J & K)

VBA Code:
Sub IndentCell()
Dim i As Integer

For i = 1 To 9
 Range("J" & i).IndentLevel = Range("K" & i)
Next

End Sub
1678981054781.png
 
Upvote 0
Solution
Having 1 for no indent makes no sense to me. If it were zero then something like this should work (I just used a loop from 1 to 9 with 9 rows as a test, in col's J & K)

VBA Code:
Sub IndentCell()
Dim i As Integer

For i = 1 To 9
 Range("J" & i).IndentLevel = Range("K" & i)
Next

End Sub
View attachment 87665
Thanks Micron, that worked perfectly after a bit of tinkering! And yes, the formatting's a little questionable on the level-side...will speak with the person that delivered this to me (or just do a quick replace myself)
 
Upvote 0
If changing the levels would be a bit of work, an option is to subtract 1 in the code from whatever level you have.
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,780
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top