+ Reply to Thread
Results 1 to 7 of 7

Check Box / Hide Rows with a specific keyword in a cell

Hybrid View

Btray90 Check Box / Hide Rows with a... 10-14-2021, 01:34 PM
BadlySpelledBuoy Re: Check Box / Hide Rows... 10-14-2021, 02:02 PM
Btray90 Re: Check Box / Hide Rows... 10-14-2021, 03:17 PM
ptmuldoon Re: Check Box / Hide Rows... 10-14-2021, 02:42 PM
ptmuldoon Re: Check Box / Hide Rows... 10-14-2021, 04:25 PM
Btray90 Re: Check Box / Hide Rows... 10-15-2021, 06:30 PM
BadlySpelledBuoy Re: Check Box / Hide Rows... 10-16-2021, 02:56 AM
  1. #1
    Registered User
    Join Date
    04-04-2013
    Location
    Hoboken, NJ
    MS-Off Ver
    Excel 365
    Posts
    28

    Check Box / Hide Rows with a specific keyword in a cell

    Hi All,
    Been awhile since I've been on here, so hopefully the community is still as vibrant as when I asked questions 8 years ago!

    I have a worksheet where there is a column (Column I) with keywords meant to abbreviate another part of that row. For example, in the cells are keywords such as "PPV", "FN", or "FNP." Those keywords are there for the purpose of grouping together like items for calculating a Sumproduct bottomline.

    On the top of this worksheet, I'd like to have a checkbox. Whenever I check the Box that is labeled as "PPV", I would like to hide the rows that are labeled anything but "PPV." Same for "FN." When I check that box, hide everything but "FN."

    I found a video where I can hide select rows using a Macro, but this worksheet is a couple hundred rows long and I don't want to have to input each individual row to isolate just the "PPV" rows. Also, I'll be adding to this file regularly.

    Any thoughts on how to best deliver this output? I am thinking it might be a function related to |=IF ("FN") Then Hide Row| if "PPV" is checked, etc.

    Thank You!
    Brian (BTray90)

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,952

    Re: Check Box / Hide Rows with a specific keyword in a cell

    Hi and welcome back

    It would help if we could see an example workbook. Depending on your data layout it may be possible to have a very simple piece of code attached to each check box that would filter the data based on a specified rule.
    Or you could loop through the rows and hide any that don't meet the criteria.

    Simple enough to do (possibly) but all depends on seeing that file.

    BSB

  3. #3
    Registered User
    Join Date
    04-04-2013
    Location
    Hoboken, NJ
    MS-Off Ver
    Excel 365
    Posts
    28

    Re: Check Box / Hide Rows with a specific keyword in a cell

    Thanks BSB and ptmuldoon for the quick replies! Attached is an example of the file in which I am trying to manipulate.

    In Cell F2 is the Check Box. If that is checked, I would like for Rows 9,10,13,15,17,18,22,25,28 and 30 to either be hidden or collapsed (if I were to set up a row collapse). These are all the non-PPV rows.
    Similarly for Rows between 47-69 when "PPV" is checked. This is just examples of two years, but I have about 10 years worth of data (not included).

    Furthermore, at some point I would also like to be able to create something similar where I can have a check box for a "FOX" filter and hide all rows that are not "FOX" from column A.


    Thank You!
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    863

    Re: Check Box / Hide Rows with a specific keyword in a cell

    It's been sometime myself with any large macro work. But you do not need to input each row to check. You can just loop your range and hide/unhide the rows as needed.

    This below looks at column I (column 9) and compares to the value in cell A1 to hide it or not.

    And perhaps instead of checkbox, use a dropdown selector with an onchange event.

    If you can post a sample, we can help more.

    Sub HideRows()
    
        Dim sht As Worksheet
        Dim r As Long, lrow As Long
        
         Application.ScreenUpdating = False
         Application.Calculation = xlCalculationManual
         
        Set sht = ActiveSheet
        lrow = sht.UsedRange.Rows(sht.UsedRange.Rows.Count).Row
    
    
        For r = lrow To 3 Step -1
            'Unhide Row
            sht.Rows(r).EntireRow.Hidden = False
            
            If Cells(r, 9).Value <> Range("A1").Value Then
            Rows(r).EntireRow.Hidden = True
            End If
        Next r
        
        Application.ScreenUpdating = True
        Application.Calculation = xlCalculationAutomatic
        
    End Sub

  5. #5
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    863

    Re: Check Box / Hide Rows with a specific keyword in a cell

    I know this can be done better, and could definitely cut down on the nested IF statements. But wanted to try and get you something before heading home today.

    Normal module and assigning each shape to the macro. See the attached as well.

    Sub HideRows()
    
        Dim sht As Worksheet
        Dim r As Long, lrow As Long
        
         Application.ScreenUpdating = False
         Application.Calculation = xlCalculationManual
         
        Set sht = ActiveSheet
        lrow = Range("H8").End(xlDown).Row
    
        'Hide all Rows
        For r = lrow To 8 Step -1
            sht.Rows(r).EntireRow.Hidden = True
            
        Next r
        
        'UnHide checked items
        For r = lrow To 8 Step -1
            'PPV
            If ActiveSheet.Shapes("Check Box 5").OLEFormat.Object.Value = 1 Then
                If Cells(r, 8).Value = "PPV" Then
                    Rows(r).EntireRow.Hidden = False
                End If
            End If
            
            'FN
            If ActiveSheet.Shapes("Check Box 6").OLEFormat.Object.Value = 1 Then
                If Cells(r, 8).Value = "FN" Then
                    Rows(r).EntireRow.Hidden = False
                End If
            End If
            
            'FNP
            If ActiveSheet.Shapes("Check Box 7").OLEFormat.Object.Value = 1 Then
                If Cells(r, 8).Value = "FNP" Then
                    Rows(r).EntireRow.Hidden = False
                End If
            End If
            
        Next r
        
    
        
        Application.ScreenUpdating = True
        Application.Calculation = xlCalculationAutomatic
        
    End Sub
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    04-04-2013
    Location
    Hoboken, NJ
    MS-Off Ver
    Excel 365
    Posts
    28

    Re: Check Box / Hide Rows with a specific keyword in a cell

    Really cool! Thanks ptmuldoon! How do you get Rows 47-69 to hide/unhide also when the boxes are checked/unchecked? It looks like only the Year A data is changing.

  7. #7
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,952

    Re: Check Box / Hide Rows with a specific keyword in a cell

    Try this slightly rewritten version of ptmuldoon's code.
    Sub HideRows()
        Dim lrow As Long
        Dim r As Long
    
        With Application
            .ScreenUpdating = False
            .Calculation = xlCalculationManual
        End With
    
        With ActiveSheet
            'UnHide all Rows
            .UsedRange.EntireRow.Hidden = False
            
            lrow = .Cells(Rows.Count, "A").End(xlUp).Row
            
            'Hide checked items
            For r = lrow To 8 Step -1
                'PPV
                If .Shapes("Check Box 5").OLEFormat.Object.Value = -4146 Then
                    If Cells(r, 8).Value = "PPV" Then Rows(r).EntireRow.Hidden = True
                End If
                
                'FN
                If .Shapes("Check Box 6").OLEFormat.Object.Value = -4146 Then
                    If Cells(r, 8).Value = "FN" Then Rows(r).EntireRow.Hidden = True
                End If
            
                'FNP
                If .Shapes("Check Box 7").OLEFormat.Object.Value = -4146 Then
                    If Cells(r, 8).Value = "FNP" Then Rows(r).EntireRow.Hidden = True
                End If
            Next r
        End With
        
        With Application
            .ScreenUpdating = True
            .Calculation = xlCalculationAutomatic
        End With
    End Sub
    BSB
    Last edited by BadlySpelledBuoy; 10-16-2021 at 08:13 AM.

+ 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. How to hide some rows based on a specific cell value whilst keeping all unused rows hidden
    By Consultant101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-15-2021, 06:41 PM
  2. How to hide all rows that don't contain a cell with a specific value
    By jgc123 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-12-2019, 01:05 PM
  3. How to check if keyword is in cell
    By ccastell88 in forum Excel General
    Replies: 1
    Last Post: 06-22-2016, 12:00 AM
  4. [SOLVED] First unhide all rows - then hide rows based on specific cell value for a range of cells
    By robbiekh in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-22-2013, 05:46 PM
  5. Using check boxes to hide and un-hide rows with drop down lists within rows
    By Sparky_Chris in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-24-2012, 07:22 AM
  6. Filter only the rows, which contain a specific keyword
    By rowdy2k5 in forum Excel General
    Replies: 2
    Last Post: 11-14-2011, 07:10 PM
  7. Hide all rows where one specific cell in that row = 0?
    By jaydevil in forum Excel General
    Replies: 2
    Last Post: 08-26-2005, 09:48 AM

Tags for this Thread

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