I am using a VBA code to filter Date and a subject name to perform some analysis. The date filtering is working all fine but I am not able to filter the subject name using an InputBox. I am assigning the the InputBox to an Object a and calling it in the filter but it gives me Run-time Error 1004, Application defined or Object Defined error.
Here is my code. Could anybody please help me with resolving the issue? I am facing error with the Subject Name filtering.
Sub Quality_Check()
'
' Quality_Check Macro
'
'
Dim dte As Date
Dim a As String
Dim score As Integer
mBox = InputBox("Enter a date")
If IsDate(mBox) Then
dte = CDate(mBox)
Dim Lastrow As Long
Lastrow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
ActiveSheet.Range("A1:AB" & Lastrow).AutoFilter field:=1, Criteria1:=">=" & dte, _
Operator:=xlAnd, Criteria2:="<" & dte 1
End If
a = InputBox("Enter the Subject Name")
With Sheets("Raw Data")
.Range("A1").Select
.Range(ActiveCell, Selection.End(xlDown)).Select
.Range(Selection, Selection.End(xlToRight)).Select
End With
Selection.AutoFilter field:=7, Criteria:=a
Selection.Copy
Sheets("Filtered").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End Sub
CodePudding user response:
It should be Criteria1
not Criteria
Selection.AutoFilter field:=7, Criteria1:=a
You can refer to the following question