Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Apr 2001
    Location
    Dallas, Texas, USA
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VisualBasic Macro to Indent (Off 2002/XP Pro SP1)

    I'm in need of some VisualBasic help. See the attached spreadsheet. What I need to do is:

    . test values in col A (the values can always be different)
    . if "1" then indent the adjacent cells in col B and col C one time
    . if "2" then indent the adjacent cells in col B and col C two times
    . if "3" and so on indent the appropriate number of times in the adjacent cells on col B and col C

    once all the tests and indents are made then hide col A from viewing.

    As always, I appreciate your taking your valuable time to help out a VisualBasic "challenged" person....... <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VisualBasic Macro to Indent (Off 2002/XP Pro SP1)

    Here is a macro that will do what you want:

    Sub IndentFromA()
    Dim oRange As Range
    Dim oCell As Range
    Set oRange = Range(Range("A1"), Range("A65536").End(xlUp))
    For Each oCell In oRange
    If IsNumeric(oCell) Then
    If oCell > 0 And oCell < 16 Then
    oCell.Offset(0, 1).Resize(1, 2).IndentLevel = oCell
    End If
    End If
    Next oCell
    Set oCell = Nothing
    Set oRange = Nothing
    ' optional
    Range("A1").EntireColumn.Hidden = True
    End Sub

    Note: column A does not need to be visible for the macro to run. You can hide it manually, and remove the last instruction before End Sub.

  3. #3
    New Lounger
    Join Date
    Apr 2001
    Location
    Dallas, Texas, USA
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VisualBasic Macro to Indent (Off 2002/XP Pro SP1)

    Wow...your response Hans was so incredibly fast it was mind boggling. Thanks very, very much for the help. I've copy/pasted your code into a macro and it works great. Thanks again.... <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •