VBA filters with helper row

Swi1ch

New Member
Joined
Aug 15, 2019
Messages
4
So I currently have a userform setup to hide a bunch of columns, and then buttons to reveal sets of columns as I want to look at them. It works fine, here is a snippet of my code for reference:
Code:
Private Sub UserForm_Initialize()
Columns.EntireColumn.Hidden = False
Rows.EntireRow.Hidden = False
ActiveWindow.FreezePanes = False
Rows("5").Hidden = True
Columns("A:C").Hidden = True
Columns("E:J").Hidden = True
Columns("L:BH").Hidden = True
Columns("AT:BG").Hidden = True
Columns("BJ").Hidden = True
End Sub
Code:
Private Sub Photography_Filter_Click()
Columns("AB:AC").Hidden = False
Columns("BG").Hidden = False

So the super obvious issue with this is if any columns are added or deleted from the sheet, it ruins all my filters immediately and I have to spend ages adjusting them in VBA. What I would like to do is set up a helper row that I can tag with an indentifier (E.G, for my photography filter I could have "PH01"), and instead of having the code hide a specific column based on my input directly in the code, have it check the helper cell and hide based on the ID tag.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hello,

Code:
For MY_COLS = 1 To ActiveSheet.UsedRange.Columns.Count
        If Cells(1, MY_COLS).Value = "PH01" Then
            Columns(MY_COLS).Hidden = False
        End If
    Next MY_COLS

Have assumed that row 1 will be the tag row.Have also assumed that data is present in all columns from A onwards.

The code will need to be launched from selection of the userform.

You will need to do something similar for the Initialize codefor columns D,K etc.

Actually, you could have a piece of code from the USERFORM to determine the filter than have the above code

Code:
For MY_COLS = 1 To ActiveSheet.UsedRange.Columns.Count
        If Cells(1, MY_COLS).Value = MY_CHOICE Then
            Columns(MY_COLS).Hidden = False
        End If
    Next MY_COLS
Does this help at all?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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