Help with VB script to hide rows

TyeReece

Board Regular
Joined
Aug 3, 2007
Messages
136
I have an VB form with 5 combo or text boxes that hides rows in a sheet based on values in the form and columns in the worksheet (Gender, Age, IQ, level of care and on site school). It works fine if I only hide based on 1 of the combo/text boxes, but when I try to hide based on more than one, it unhides a row that is already hidden. How do I get the code to only hide the rows that meet the criteria and are visible when the code loops through? Below is part of the code and I imagine this is


Private Sub btnFiltered_Click()
SetSheetNames
If cboGender.Text = "Male" Then
FilterPrograms.HideMale = 0
FilterPrograms.HideFemale = 1
ElseIf cboGender.Text = "Female" Then
FilterPrograms.HideMale = 1
FilterPrograms.HideFemale = 0
ElseIf cboGender.Text = "" Then
FilterPrograms.HideMale = 0
FilterPrograms.HideFemale = 0
End If
If cboOnSiteSchool.Text = "Yes" Then
FilterPrograms.HideNoOnSiteSchool = 1
ElseIf cboOnSiteSchool.Text = "No" Then
FilterPrograms.HideNoOnSiteSchool = 0
ElseIf cboOnSiteSchool.Text = "" Then
FilterPrograms.HideNoOnSiteSchool = 0
End If
ShowHideSheets SheetNames.ComparisonTable
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Me.Hide
End Sub



Thanks in advance
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,670
Messages
5,838,689
Members
430,564
Latest member
Raeyven

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
Top