I have a code that filters data in a userform however, it will only work if most of the boxes are filled, how to i get my below code to filter if only a few of the filter boxes are filled in.
VBA Code:
Private Sub cmdfilter_Click()
Dim ws As Worksheet
'set worksheet variable
Set ws = Sheet1
'Make sure it is a proper date
If Not IsDate(Me.txtDateStart) And Me.txtDateStart <> "" Then
MsgBox "This is not a proper date"
Me.txtDateStart = ""
Exit Sub
End If
'Make sure it is a proper date
If Not IsDate(Me.txtDateTo) And Me.txtDateTo <> "" Then
MsgBox "This is not a proper date"
Me.txtDateStart = ""
Exit Sub
End If
With ws
.Range("C4").Value = Format(Me.txtDateStart.Value, "mm/dd/yyyy")
.Range("D4").Value = Format(Me.txtDateTo.Value, "mm/dd/yyyy")
.Range("E4").Value = Me.cboTCO1.Value
.Range("E5").Value = Me.cboTCO2.Value
.Range("E6").Value = Me.cboTCO3.Value
.Range("E7").Value = Me.cboTCO4.Value
.Range("F4").Value = Me.cboCallType1.Value
.Range("F5").Value = Me.cboCallType2.Value
.Range("F6").Value = Me.cboCallType3.Value
.Range("F7").Value = Me.cboCallType4.Value
.Range("G4").Value = Me.txtCRM1.Value
.Range("G5").Value = Me.txtCRM2.Value
.Range("G6").Value = Me.txtCRM3.Value
.Range("G7").Value = Me.txtCRM4.Value
End With
'Run the advanced filter
FilterMe
'add the named range to the rowsource
If ws.Range("C14").Value = "" Then
Me.lstData.RowSource = ""
MsgBox "No Matching Data"
Else
Me.lstData.RowSource = "FilterData"
End If
End Sub