+ Reply to Thread
Results 1 to 11 of 11

Indenting cells with VBA where value in another cell matches criteria

  1. #1
    Registered User
    Join Date
    10-19-2007
    Posts
    29

    Indenting cells with VBA where value in another cell matches criteria

    Hi

    Firstly, I would just like to confirm that I have searched until my eyes bled and haven't been able to find what I need to resolve my problem!

    Secondly, what I am trying to achieve is to have the text in a cell indent automatically if the value in another cell meets a specific criterion. I have attached the relevant worksheet from a wider workbook (nothing in the other worksheets relates to this particular workbook).

    plan.xlsm

    The objective is that if a project manager selects L3 as a value in column B, the text in column E will indent by 1 (signifying that the entry is a sub-task or milestone of the L2 milestones which the entry should sit under). I found some VBA which I thought would do the trick and I have left that in the workbook and also posted it here (apologies because I have lost track of where it originated in the first place) but I can't get it working.

    Please Login or Register  to view this content.
    I would prefer not to rely on users creating their plans with relevant milestone levels and then pressing a button to run a macro to indent the relevant cells but, if the consensus is that it is the best way to go, I am happy to follow the crowd. Grateful for any help.

    Thanks
    Nicki
    Last edited by barefaced66; 01-19-2015 at 10:50 AM.

  2. #2
    Registered User
    Join Date
    05-13-2014
    Location
    Best
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Indenting cells with VBA where value in another cell matches criteria

    I don't quite understand the problem!
    Col B has a DDbox attached. I can't see any numeric values under it.
    OK
    If you enter 10 in column B : Do you want to indent row 16 by 1 indent?

  3. #3
    Registered User
    Join Date
    10-19-2007
    Posts
    29

    Re: Indenting cells with VBA where value in another cell matches criteria

    Quote Originally Posted by bart hoekstra View Post
    I don't quite understand the problem!
    Col B has a DDbox attached. I can't see any numeric values under it.
    OK
    If you enter 10 in column B : Do you want to indent row 16 by 1 indent?
    Bart - my bad. There is a hidden helper column C which contains a formula so that if the user selects L2 in Column B, the helper cell value is 0 and if they select L3, the helper cell value is 1 - then I want to reference the value in the helper cell via VBA to indent the entry in column E - does that make more sense?

    N

  4. #4
    Registered User
    Join Date
    05-13-2014
    Location
    Best
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Indenting cells with VBA where value in another cell matches criteria

    Try this
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Range("D:D"), Range(Cells(Target.Row, 1), "$D" & Target.Row)) Then
    If Range("$D" & Target.Row).Value > 0 Then Range("$e" & Target.Row).IndentLevel = Range("$D" & Target.Row).Value
    End If
    End Sub

  5. #5
    Registered User
    Join Date
    05-13-2014
    Location
    Best
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Indenting cells with VBA where value in another cell matches criteria

    Try this
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Range("D:D"), Range(Cells(Target.Row, 1), "$D" & Target.Row)) Then
    If Range("$D" & Target.Row).Value > 0 Then Range("$e" & Target.Row).IndentLevel = Range("$D" & Target.Row).Value
    End If
    End Sub

  6. #6
    Registered User
    Join Date
    05-13-2014
    Location
    Best
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Indenting cells with VBA where value in another cell matches criteria

    Hi here's the modified sheet:
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    10-19-2007
    Posts
    29

    Re: Indenting cells with VBA where value in another cell matches criteria

    Quote Originally Posted by bart hoekstra View Post
    Hi here's the modified sheet:
    That looks perfect, thank you
    N

  8. #8
    Registered User
    Join Date
    10-19-2007
    Posts
    29

    Re: Indenting cells with VBA where value in another cell matches criteria

    Quote Originally Posted by bart hoekstra View Post
    Hi here's the modified sheet:
    That looks perfect, thank you
    N

  9. #9
    Registered User
    Join Date
    10-19-2007
    Posts
    29

    Re: Indenting cells with VBA where value in another cell matches criteria

    Ok, not quite solved yet. How do I amend the VBA so that if a user selects L3 in Col B (and so the contents of the cell in Col E are indented) and then changes the entry in Col B back to L2, the contents of the cell in Col E revert back to being 0 indented?

    Thanks
    N

  10. #10
    Registered User
    Join Date
    05-13-2014
    Location
    Best
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Indenting cells with VBA where value in another cell matches criteria

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Range("D:D"), Range(Cells(Target.Row, 1), "$D" & Target.Row)) Then
    Range("$e" & Target.Row).IndentLevel = Range("$D" & Target.Row).Value
    Else
    If Range("$e" & Target.Row).IndentLevel > 0 Then Range("$e" & Target.Row).InsertIndent -1
    End If
    End Sub

  11. #11
    Registered User
    Join Date
    10-19-2007
    Posts
    29

    Re: Indenting cells with VBA where value in another cell matches criteria

    Bart - you are a star, thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Tabbing/Indenting within a cell
    By DianeMcP in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 07-29-2020, 01:24 PM
  2. [SOLVED] Populating cells with data that matches certain criteria
    By coach.32 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-17-2013, 10:13 PM
  3. Replies: 5
    Last Post: 10-19-2012, 07:42 AM
  4. If values in 2 cells matches criteria, add text to a third cell
    By Zarkov in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-31-2011, 03:14 PM
  5. Indenting cells in Excel
    By Beth in forum Excel General
    Replies: 2
    Last Post: 03-03-2005, 09:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1