Hello Winner_Texas,
I wanted to make this change as simple as possible. So, I added another argument on to the HideRows macros. The arguments now are: Match Term (string), ControlID (integer), HideOnMatch (boolean). The last argument determines if the row is to be hidden when the match term, what you are searching for, is found (True) or to hide all other rows that do not match the search term (False). Here are the updates that have been added to the new workbook.
Module1 Macro Code
Public HiddenRng(4) As Range
Sub HideRows(ByVal MatchTerm As String, ByVal CtrlId As Integer, HideOnMatch As Boolean)
Dim Cell As Range
Dim HideRng As Range
Dim I As Integer
Dim R As Long
Dim Rng As Range
Dim RngEnd As Range
Dim Wks As Worksheet
I = CtrlId - 1
Set Wks = Worksheets("Sheet1")
Set Rng = Wks.Range("A2")
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Wks.Range(Rng, RngEnd)
For R = Rng.Row To (Rng.Rows.Count + Rng.Row - 1)
Set Cell = Wks.Cells(R, 1)
If HiddenRng(I) Is Nothing Then Set HiddenRng(I) = Cell
If InStr(1, Cell.Text, MatchTerm, vbTextCompare) Then
If HideOnMatch Then Set HiddenRng(I) = Union(HiddenRng(I), Cell)
Else
If Not HideOnMatch Then Set HiddenRng(I) = Union(HiddenRng(I), Cell)
End If
Next R
HiddenRng(I).EntireRow.Hidden = True
End Sub
Sub ShowRows(ByVal CtrlId As Integer)
If Not HiddenRng(CtrlId - 1) Is Nothing Then
HiddenRng(CtrlId - 1).EntireRow.Hidden = False
End If
End Sub
Sheet1 CheckBox Macro Code
Private Sub CheckBox1_Change()
If CheckBox1 = True Then
HideRows "Current", 1, True
Else
ShowRows 1
End If
End Sub
Private Sub CheckBox2_Change()
If CheckBox2 = True Then
HideRows "Improv", 2, True
Else
ShowRows 2
End If
End Sub
Private Sub CheckBox3_Change()
If CheckBox3 = True Then
HideRows "New", 3, True
Else
ShowRows 3
End If
End Sub
Private Sub CheckBox4_Change()
If CheckBox4 = True Then
HideRows "Final", 4, True
Else
ShowRows 4
End If
End Sub
Private Sub CheckBox5_Click()
If CheckBox5 = True Then
HideRows "Cash Flow", 5, False
Else
ShowRows 5
End If
End Sub
.
Bookmarks