VBA - button to hide rows based on value in a column

ad1234

Board Regular
Joined
Jan 16, 2008
Messages
163
I am creating a UserForm with various functions using buttons but I want to "move on" from autofiltering or other methods I've used before.

I have a range "all_rows_summary" defined as "=Summary!$3:$204"

The range "gender" is defined as "=Summary!$F$3:$F$250" and has the value (which is the result of a formula shown in the cells) of "F" and "M" (which is the result of a VLookup formula shown in a cell).

I want to write a function for to "Show Boys" that hides all the rows with an "F" in the range "gender"...

I have looked on here and tried but can't get past initial errors... This is what I have so far:

Code:
Private Sub CommandButton1_Click()

If Range("gender").Value = "F" Then


Range("all_rows_summary").EntireRow.Hidden = True


End If


End Sub

I want to then reuse the code for other similar functions... Many thanks in advance
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
What's wrong with autofilter. I use it all the time.

Otherwise, loop through each row 3 to 250 and show\hide them individually based on if Range("F" & row) = "F"
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,821
Members
449,049
Latest member
cybersurfer5000

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