I am unable to determine why I am getting this error for the code below. The listbox rowsource is correct and the advanced filter leaves the active page on the rowsource page. In this project I have a combo and text box that searches for the criteria. Is it not possible for the text box to search headers that are columns of text (i.e Name, Position, Training TItle)..., and columns of numbers (i.e. ID, Serial#, Year...)? I can use the code below and will return to the list box the entire data set, but when I search for a letter or a number I get this error.
Simple I know, but need help please.
Simple I know, but need help please.
Rich (BB code):
Private Sub cmdSearch_Click()
Dim Crit As Range
Dim FindMe As Range
Dim DataSH As Worksheet
Dim TrngRptSH As Worksheet
Set DataSH = Sheet8
Set TrngRptSH = Sheet18
On Error GoTo errHandler:
Application.ScreenUpdating = False
If Not IsDate(Me.txtRpt1) And Me.txtRpt1 <> "" Then
MsgBox "This is not a proper date format mm/dd/yyyy"
Me.txtRpt1 = ""
Exit Sub
End If
If Not IsDate(Me.txtRpt2) And Me.txtRpt2 <> "" Then
MsgBox "This is not a proper date format mm/dd/yyyy"
Me.txtRpt2 = ""
Exit Sub
End If
If Me.cboRpt1.Value <> "All_Columns" Then
If Me.cboRpt1 = "" Then
TrngRptSH.Range("V3") = ""
TrngRptSH.Range("V2") = ""
TrngRptSH.Range("T3") = ""
TrngRptSH.Range("U3") = ""
Else
TrngRptSH.Range("V3") = "*" & Me.txtRpt3.Value & "*"
TrngRptSH.Range("V2") = "*" & Me.cboRpt1.Value & "*"
TrngRptSH.Range("T3") = Format("*" & Me.txtRpt1.Value & "*", "mm/dd/yyyy")
TrngRptSH.Range("U3") = Format("*" & Me.txtRpt2.Value & "*", "mm/dd/yyyy")
End If
End If
If Me.cboRpt1.Value = "All_Columns" Then 'HistData4[#All]
Set FindMe = DataSH.Range("HistData4").Find(What:=Me.txtRpt3, LookIn:=xlValues, _
lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
Set Crit = TrngRptSH.Cells(2, FindMe.Column)
If Me.cboRpt1 = "" Then
TrngRptSH.Range("V3") = ""
TrngRptSH.Range("V2") = ""
TrngRptSH.Range("T3") = ""
TrngRptSH.Range("U3") = ""
Else
TrngRptSH.Range("V2") = Crit
If Crit = "ID" Then
TrngRptSH.Range("V3") = Me.txtRpt3.Value
Else
TrngRptSH.Range("V3") = "*" & Me.txtRpt3.Value & "*"
End If
Me.txtAllColumn = TrngRptSH.Range("V2").Value
End If
End If
Unprotect_All
AdvFilterTrngRpt
lstRpt1.RowSource = TrngRptSH.Range("FilterTrngRpt").Address(external:=True) ' <<<<<<<<<error point
txtRec_Num1.Text = ActiveSheet.Range("T6").Value
SortRpt
PvtSearch
Protect_All
On Error GoTo 0
Exit Sub
errHandler::
Protect_All
MsgBox "An Error has Occurred " & vbCrLf & "The error number is: " _
& Err.Number & vbCrLf & Err.Description & vbCrLf
Exit Sub
End Sub
Sub AdvFilterTrngRpt()
Sheets("Data").Range("HistData4[#All]").AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheet18.Range("TrngRpt!Criteria"), CopyToRange:=Sheet18.Range( _
"TrngRpt!Extract"), Unique:=False
End Sub
Last edited by a moderator: