J
Jonathan Brown
I have a column that has a list of site names. I need some sort of a
function that'll search through the column and hide each row that contains
the value of a string variable. the function will be run when I uncheck a
checkbox.
And then when I recheck the checkbox I need it to unhide those rows. I've
been trying to figure this out using a loop but I don't think I'm doing it
correctly.
According to the code that I've written it's supposed to start at the top of
the column and find the first instance of a cell that matches my Site
variable and then assign the row number to the StartRow variable and then
continuing until it finds the last instance of the Site variable and assign
the row number to the EndRow variable. And then I use the Rows(StartRow &
":" & EndRow).hidden = true function.
The problem with this is that it assumes that all of my sites are going to
be grouped together in a contiguous block, which will not always be the case.
Here's my code:
------------------------------------------------------------------------------------------
Dim SiteRange As String
Dim Counter As Int16 = 1
Dim SearchCriteria As String
Dim StartRow As String
Dim EndRow As String
Dim MyFilterRange As String
SiteRange = Sheets("Masson-Predator").Cells(Counter, 5) 'Start at
the top of the column.
SearchCriteria = "China Lake CLS"
Do Until SiteRange = SearchCriteria 'Loop through the cells in the
sites column.
StartRow = Counter
Counter = Counter + 1
Do Until SiteRange <> SearchCriteria
EndRow = Counter - 1
MyFilterRange = StartRow & ":" & EndRow
Loop
Loop
If Me.cboChinaLakeCLS.Checked = False Then
Sheets("Masson-Predator").Rows(MyFilterRange).Hidden = True
Else
Sheets("Masson-Predator").Rows(MyFilterRange).Hidden = False
End If
function that'll search through the column and hide each row that contains
the value of a string variable. the function will be run when I uncheck a
checkbox.
And then when I recheck the checkbox I need it to unhide those rows. I've
been trying to figure this out using a loop but I don't think I'm doing it
correctly.
According to the code that I've written it's supposed to start at the top of
the column and find the first instance of a cell that matches my Site
variable and then assign the row number to the StartRow variable and then
continuing until it finds the last instance of the Site variable and assign
the row number to the EndRow variable. And then I use the Rows(StartRow &
":" & EndRow).hidden = true function.
The problem with this is that it assumes that all of my sites are going to
be grouped together in a contiguous block, which will not always be the case.
Here's my code:
------------------------------------------------------------------------------------------
Dim SiteRange As String
Dim Counter As Int16 = 1
Dim SearchCriteria As String
Dim StartRow As String
Dim EndRow As String
Dim MyFilterRange As String
SiteRange = Sheets("Masson-Predator").Cells(Counter, 5) 'Start at
the top of the column.
SearchCriteria = "China Lake CLS"
Do Until SiteRange = SearchCriteria 'Loop through the cells in the
sites column.
StartRow = Counter
Counter = Counter + 1
Do Until SiteRange <> SearchCriteria
EndRow = Counter - 1
MyFilterRange = StartRow & ":" & EndRow
Loop
Loop
If Me.cboChinaLakeCLS.Checked = False Then
Sheets("Masson-Predator").Rows(MyFilterRange).Hidden = True
Else
Sheets("Masson-Predator").Rows(MyFilterRange).Hidden = False
End If