VBA | Filter Multiple Columns Based On Single Cell Value

foolishpiano

New Member
Joined
Aug 19, 2016
Messages
28
Hi all!

I have a named range - "States" - that are column headers. I would like to filter the columns in this named range based state selection in another cell (F1). If the State selected in cell F1 equals a state in the Named Range, keep that column visible, but hide the other columns. I'm not sure how to upload a copy of the workbook I'm creating, but I am including a screenshot of what I'm working on.

Essentially, what I'm after is if my user selects the state 'MO' in cell F1 (for example), columns E, F, G, S, and V would be the only columns visible, and all others would be hidden.

Is such a thing possible?

Thank you all for the help, as always!

1649088757897.png
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hello everyone (again).

Just wanted to let everyone know that I figured out the answer to my question. This thread helped with part of it, and using the information in that thread, I came up with the following code (important note: I moved my state-selection column from F1 to D1):

VBA Code:
Private Sub worksheet_change(ByVal target As Range)

If target.Address = "$D$1" Then
For Each cl In Sheets("Data for Checklist - Properties").Range("States")
    cl.EntireColumn.Hidden = Not (IsNumeric(Application.Match(cl, Array(Range("D1").Value), 0)))
    Next
End If

If Range("D1").Value = "" Then

Range("States").EntireColumn.Hidden = False

End If


End Sub

Just wanted to add this solution in case someone else comes along with this same question.

Thanks!
 
Upvote 0
Solution

Forum statistics

Threads
1,216,113
Messages
6,128,905
Members
449,478
Latest member
Davenil

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