![]() |
User Form to Filter by Multiple Criteria
Good day,
I need to create a User Form (Excel 2003) that allows users to enter 5 filter criteria. Each filter must allow input for a single Column letter (e.g., A, B, C), single operand (e.g., =, , <, ) and single criteria (e.g., A1500, 100.00). Any suggestions? I tried building a filter string (shown below). ***** Dim strField1 As String, ... 'Filter 1 strFilter = IIf(Me.txtField1.Value = "", "", _ ".AutoFilter Field:=" & Me.txtField1.Value & ", " & _ "Criteria:='" & Me.cboOperand1.Value & Me.txtValue1.Value & "'") 'Filter 2 strFilter = IIf(Me.txtField2.Value = "", strFilter, _ strFilter & ", Operator:=xlAnd .AutoFilter Field:=" & Me.txtField2.Value & ", " & _ "Criteria:='" & Me.cboOperand2.Value & Me.txtValue2.Value & "'") '(same code for Filters 3, 4, and 5) 'Run the filter If strFilter = "" Then MsgBox "You must enter at least one filter." GoTo Exit_Sub Else Set rng = ActiveSheet.AutoFilter.Range With rng strFilter End With End If 'Exit sub Exit_Sub: Exit Sub 'Error handler Err_Handler: MsgBox "Error: " & Err GoTo Exit_Sub End Sub ***** Regards, Dan |
All times are GMT +1. The time now is 08:52 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com