OzGrid

How to indent based on corresponding cell value

< Back to Search results

 Category: [Excel]  Demo Available 

How to indent based on corresponding cell value

 

Requirement:

 

The user trying to do some automatic formatting of a list of data to create an indented BOM structure.

The user wants to set the Indent Level for Column B by values in Column A. i.e. a value of 1 in Cell A1 indents Cell B1 by 1.

Solution:

 

Right click the sheet tab and paste this code in the sheet code module.

Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Range("A:A"), Target) Is Nothing Then
        If IsNumeric(Target.Value) Then
            If Target.Value >= 0 Then
                Target.Offset(0, 1).IndentLevel = Target.Value
            End If
        End If
    End If
End Sub

 

Obtained from the OzGrid Help Forum.

Solution provided by Andy Pope.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

How to use a Macro to copy rows from multiple worksheets based on a cell value greater than zero
How to remove the last X number of characters depending on the ending of the value

 

How to sum cell numerical values based on text suffix
How to sort values in positive and negative numbers with formula

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


Gallery



stars (0 Reviews)