Method range of object _worksheet failed 1004 vba

Rfriend

Board Regular
Joined
May 10, 2021
Messages
73
Office Version
  1. 2010
Platform
  1. Windows
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.

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:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Change your code:
Me.txtRpt1 should be Me.txtRpt1.Text
Me.txtRpt2 should be Me.txtRpt2.Text
VBA Code:
    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

As the above is trying to act on the Textbox Object
 
Upvote 0
Most likely there isn't a range called FilterTrngRpt or it isn't on the specified sheet.
 
Upvote 0
Most likely there isn't a range called FilterTrngRpt or it isn't on the specified sheet.
FilterTrngRpt is the dynamic named range far the tab that hosts the results of the advance search. The search results are from sheet8 (TrngRpt). The criteria and extract range is on sheet18. The advance filter is good without criteria being entered on the user form, but the line after is where my code errors if any selections are made in (cboRpt1.value (V2) & (txtRPt3.text (V3))

VBA Code:
 AdvFilterTrngRpt

[/QUOTE]
lstRpt1.RowSource = TrngRptSH.Range("FilterTrngRpt").Address(external:=True)
 

Attachments

  • Capture.PNG
    Capture.PNG
    59.4 KB · Views: 6
Upvote 0
Change your code:
Me.txtRpt1 should be Me.txtRpt1.Text
Me.txtRpt2 should be Me.txtRpt2.Text
VBA Code:
    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

As the above is trying to act on the Textbox Object
I added or changed the extension as directed. I still error in the line of code after the adv filter runs.
 

Attachments

  • Capture2.PNG
    Capture2.PNG
    28.2 KB · Views: 10
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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