VBA for sorting and showing only selected criteria

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
458
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello... ok, here is what I need, hopefully someone here has something that will work to offer :)
I would like to have a button (as shown below in the screen shots) that when selected will sort and only show the columns with “SR” (as listed in row 3) It would hide ALL the other columns except the ones with SR in row 3… (I would then duplicate the code and have several other buttons that would do the same thing depending on what was listed in row 3, such as "CG", "PK", etc.


Here is a screen shot of an example of how it looks BEFORE hitting the button:


Here is what I need to obtain after the "Show SR" button is selected:


(Note that I also have existing code already in place that already hides every-other-column.. that's what the "Show Dates" button does.)
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
trythis

Code:
For Each cell In Range("C3:Z3").Cells
If cell = "SR" Then Columns(cell.Column).Hidden = False Else Columns(cell.Column).Hidden = True
Next
 
Last edited:
Upvote 0
Thanks! That worked... but how do I make it so when I 'deselect' the button it will go back to showing all again?
 
Upvote 0
btw... I replied to this thread just a minute or 2 before it went down for Maintenance... and now that reply is gone(?) DId it get deleted or was it due/related to what happened yesterday with the boards going down?
 
Upvote 0
Unhide

Unhide macro:
Code:
For Each cell In Range("C3:Z3").Cells
Columns(cell.Column).Hidden = False
Next
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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