Userform with VBA

Evie76

New Member
Joined
Jan 17, 2022
Messages
36
Office Version
  1. 365
Platform
  1. Windows
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.

Screenshot 2024-02-02 130410.png

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
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

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
Back
Top