Using a checkbox to unhide rows on another sheet

briggss1

Board Regular
Joined
Oct 23, 2006
Messages
64
I have the need to use a filtering cover sheet to unhide only relevant data entry fields on an adjacent sheet. Ideally I could steer clear of VBA, but if not, oh well. In principle, I am trying to do the following as per the example:

I want to select the following by clicking or adding a value next to the item using a simple alphanumeric value or even a checkbox. This is done on Sheet 1.

1681247797992.png


Once this happens, on Sheet 2 where all rows will be hidden by default, I want to unfilter (or open up/make visible) all of the rows on that respective category that contain an "x" for that category.

This is the complete table as an example wioth nothing opened or closed.
1681248032475.png


This is how the table will look with nothing checked on sheet 1 (all hidden), nothing requiring a data entry to be completed.
1681248429590.png


This is how sheet 2 will look with the items checked as indicated in my first screenshot from Sheet 1.
1681248551150.png
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I think VBA is needed for this.

On Sheet1, add a table named "CategoriesSelected" like this:

CategorySelected
Applesx
Oranges
Peachesx
Milkx
Bread
Eggs

Note that the categories are in the first column so the code can do VLOOKUP on them. Using a table, instead of a specific range, means rows can be added/removed without changing the code. The "x" can be any alphanumeric character(s) because the code looks for '<> ""' rather than '= "x"'.

Put this code in the module for Sheet2:
VBA Code:
Private Sub Worksheet_Activate()

    Dim table As ListObject
    Dim c As Long, r As Long
    Dim hideRow As Boolean
   
    Set table = ThisWorkbook.Worksheets("Sheet1").ListObjects("CategoriesSelected")

    Application.ScreenUpdating = False
   
    With Me
        .Rows.EntireRow.Hidden = False
        For r = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
            hideRow = True
            For c = 5 To .Cells(1, .Columns.Count).End(xlToLeft).Column
                If Not IsEmpty(.Cells(r, c).Value) And Application.WorksheetFunction.VLookup(.Cells(1, c).Value, table.Range, 2, False) <> "" Then
                    hideRow = False
                End If
            Next
            If hideRow Then .Rows(r).EntireRow.Hidden = True
        Next
    End With

    Application.ScreenUpdating = True
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,661
Messages
6,120,792
Members
448,994
Latest member
rohitsomani

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top