Good morning!
I've been developing a sheet for the amount of classes my business has over the year. I have a piece of code that seems to work well in filtering the data (I know auto-filters would be easier but they don't match the layout of the sheet) but I've ran into a problem. In the code below it's reading from 2 ComboBoxes currently but more will be added. If a combobox is left empty I'd like it to leave all the cells blank then move onto the next piece of code allowing multiple filtering levels. Where I'm running into the issue is in red below,
Private Sub submit_filter_Click()
Application.Calculation = xlManual
Dim DataCriteria As String, i As Long, CountA As Long
datacriteria_site = filter_nh_calendar.combobox_filter_site.Value
datacriteria_lob = filter_nh_calendar.combobox_filter_lob.Value
Rows("5:1004").EntireRow.Hidden = False
CountA = 0
Application.ScreenUpdating = False
If datacriteria_lob = "" Then
'code if null
Rows("5:1004").EntireRow.Hidden = False
Else
'filters by LOB
For i = 5 To 1004
If Cells(i, 1).Value <> datacriteria_lob Then
CountA = CountA + 1
Rows(i).EntireRow.Hidden = True
End If
Next i
End If
If datacriteria_site = "" Then
'code if null
Rows("5:1004").EntireRow.Hidden = False
Else
'filters by site
For i = 5 To 1004
If Cells(i, 5).Value <> datacriteria_site Then
CountA = CountA + 1
Rows(i).EntireRow.Hidden = True
End If
Next i
End If
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
filter_nh_calendar.Hide
Unload Me
End Sub
What I believe to be happening is that when I try and make a selection from "LOB" it accepts it but then see's that the "Site" field is empty and thus unhides everything. It works great for "Site" by itself because it's the last thing in the code I believe.
I could be completely off base here but any assistance would be greatly appreciated.
Thanks!
Bookmarks