Indent cell by a variable

biske

New Member
Joined
Oct 27, 2006
Messages
4
I have a bill of material exported from a business system. Column A contains the Level of the item in the BOM, and Column B and C have the part number and description.

I want to indent the part number and description by the level number. In other words, I want to Indent column B by the value in column A.

Is this possible, with and without VBA (which I am unfamiliar with)?

Thanks.

Brian
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Brian

How exactly do you want to indent?
 
Upvote 0
I want to indent within the cell that the text is in.

For example, if the item is at level 2 (2 in column A), I want to double indent the text in the description.
 
Upvote 0
I don't think that this can be done without VBA, except for the manual indent feature.

Here is a VBA option. Pre-select your range and run the following

Code:
Sub TEST()
Dim Cell As Range

On Error Resume Next
    For Each Cell In Selection
        With Cell
            .IndentLevel = False  '' clears any existing indents
            .InsertIndent .Offset(0, -1).Value
        End With
    Next Cell
On Error GoTo 0

End Sub
 
Upvote 0
This may seem ridiculous, but I have been using Excel for a long time, and used some of the more advanced formulas, but have never used or run VBA.

Could you explain to me how to 'run' this?

thanks
 
Upvote 0
On your first time, only have the workbook in question open. Close all other open workbooks.

From Excel, go into the Visual Basic Editor (VBE) by one of the following ways:

1. Tools>Macro>Visual Basic Editor
2. Alt+F11 key combination

Once there, hit Ctrl+R to ensure that the Project Explorer is visible. Wherever it is docked (usually on the left side), you will see a reference to your workbook. If you expand the options, you should only see a folder called Microsoft Excel Objects. Expanding further, you should see the names of the various sheets in your workbook. Each of those sheets can hold macros, but that is for later.

From the top menu, Insert > Module. In the Project Explorer, Excel will have added an additional folder called Modules. On the main part of the screen, you should see a blank sheet (or else Option Explicit), which is the code sheet (it will be called Module1 in the Project Explorer).

Copy the code for the routine into that blank section of Module1.

Close the VBE (Alt+Q) to go back to Excel.

Select the range of items in column B

Tools>Macro>Macros (shortcut key combo is Alt+F8) will bring up a dialog box. The only macro you have should be highlighted. Choose Run and the macro will process.

A lot of steps at first, but these will become second nature in no time.
 
Upvote 0
Thanks!!

That's awsome. This will same a ton of keystrokes and editing.

Thanks for helping a newbie.

Brian
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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