Consulting

Results 1 to 7 of 7

Thread: hide rows based on highlighted cell in column

  1. #1
    VBAX Regular
    Joined
    May 2016
    Posts
    69
    Location

    hide rows based on highlighted cell in column

    I am looking for a code that will hide a row and the next row when it sees a blue highlight in a cell in a specific column.
    Also, code that will reverse the rows hidden (it cant generally hide all rows because i have other rows hidden that should remain hidden)

    For hypothetical purposes it will be column C and the highlight color code will be 123.

    Thanks

  2. #2
    This should work to hide and unhide the color code 123 highlighted row and the row below.

    Sub HideRows()
    Dim Cell As Range,
    cRange As Range,
    LtRow As Long
    LtRow = ActiveSheet.Cells(Rows.Count, "C").End(xlUp).Row
    Set cRange = Range("C1:C" & LtRow)
    For Each Cell In cRange
        If Cell.Interior.ColorIndex = 123 Then
            Cell.EntireRow.Hidden = True
            Cell.Offset(0,1).EntireRow.Hidden = True
        End If
    Next Cell
    End Sub
    
    
    Sub unHideRows()
    Dim Cell As Range,
    cRange As Range,
    LtRow As Long
    LtRow = ActiveSheet.Cells(Rows.Count, "C").End(xlUp).Row
    Set cRange = Range("C1:C" & LtRow)
    For Each Cell In cRange
        If Cell.Interior.ColorIndex = 123 Then
            Cell.EntireRow.Hidden = False
            Cell.Offset(0,1).EntireRow.Hidden = False
        End If
    Next Cell
    End Sub

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    See attached with toggle button.
    Sub blah()
    'Application.ScreenUpdating = False
    With ActiveSheet.Shapes("Button 1").DrawingObject
      If .Caption = "Hide" Then
        .Caption = "Show"
        HideMe = True
      Else
        .Caption = "Hide"
        HideMe = False
      End If
      For Each cll In Intersect(ActiveSheet.UsedRange, Columns(3)).Cells
        If cll.Interior.Color = 123 Then cll.Resize(2).EntireRow.Hidden = HideMe
      Next cll
    End With
    'Application.ScreenUpdating = True
    End Sub
    or:
    Sub blah()
    'Application.ScreenUpdating = False
    With ActiveSheet
      With .Shapes("Button 1").DrawingObject
        If .Caption = "Hide" Then .Caption = "Show": HideMe = True Else .Caption = "Hide": HideMe = False
      End With
      For Each cll In Intersect(.UsedRange, .Columns(3)).Cells: If cll.Interior.Color = 123 Then cll.Resize(2).EntireRow.Hidden = HideMe
      Next cll
    End With
    'Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    VBAX Regular
    Joined
    May 2016
    Posts
    69
    Location
    Thank you both

  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by Sandler View Post
    Thank you both
    It's nice that you said 'Thank you'.
    What's not so nice is that you already had a solution to this at a cross posting at MrExcel hours ago. blanchard306 and I have wasted our time, utterly (flagged by the attachment I supplied still showing zero views). You could have said you already had a solution. I'm no moderator here (I am elsewhere) so I can't ask you to do anything.

    Forums aren't operated by a bunch of automatons, but by humans, who have feelings.

    The solution is easy; you include in your thread, links to all your cross posts, at all the forums involved. It's actually a rule at 99% of the forums. That way people can quickly check if you already have a solution and can then choose to improve on it or not, knowing how far down the line you are to getting the solution you want.

    The reasons are crystallised here: http://www.excelguru.ca/content.php?184

    Be considerate of others and they will be considerate to you. Don't be, and they won't.

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Quote Originally Posted by p45cal View Post
    I'm no moderator here (I am elsewhere) so I can't ask you to do anything.
    Yes you can p45cal, your efforts here hold you in high standings, so don't feel intimidated about asking anyone to do anything.

    Forums aren't operated by a bunch of automatons, but by humans, who have feelings.
    Who also feely give their time and effort to assist others in a quest to find answers to problems. Please don't devalue their effort to you ( in a direct sense) and the community (indirectly by way of education).
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    VBAX Regular
    Joined
    May 2016
    Posts
    69
    Location
    I agree p45cal, I apologize and will be more mindful going forward.

    I also like your spreadsheet solution, it is very concise, and it makes sense to stick a small button into the actual sheet that I want the task completed in.

Posting Permissions

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