AdvFilter will return data to named range but not show in userform list box.

Rfriend

Board Regular
Joined
May 10, 2021
Messages
73
Office Version
  1. 2010
Platform
  1. Windows
Hello,

I have a user form with a list box that is supposted to show training records returned from an advanced search. ColumnHeads = true, and the named range is correct. I can't figure out why the filter works in the workbook, but will not show the data, nor headers, in the list box. However, when I close the user form the data populated the listbox.

See code below.

VBA Code:
Private Sub cmdSearch_Click()
    Dim TrngRptSh As Worksheet
    Dim DataSH As Worksheet
    On Error GoTo errHandler:
        Set TrngRptSh = Sheet18
        Set DataSH = Sheet8

        If cboRpt1.Value = "" Then
            TrngRptSh.Range("V2") = ""
            TrngRptSh.Range("V3") = ""
            TrngRptSh.Range("T3") = ""
            TrngRptSh.Range("U3") = ""
        Else
            TrngRptSh.Range("V2") = Me.cboRpt1.Value
            TrngRptSh.Range("V3") = Me.txtRpt3.Text
            TrngRptSh.Range("U3") = Me.txtRpt2.Text
            TrngRptSh.Range("T3") = Me.txtRpt1.Text
        End If

    Unprotect_All
        Sheet8.Range("HistData4[#All]").AdvancedFilter Action:=xlFilterCopy, _             '<<<AdvFilter
        CriteriaRange:=Sheet18.Range("V2:X3"), _
        CopyToRange:=Sheet18.Range("C2:O2"), Unique:=False 
            
            SortRpt
                PvtSearch
                    Sheets("TrngRptDeptHrsMthPvt").Select
                        Range("G6").Select
                        Selection.Group Start:=True, End:=True, Periods:=Array(False, False, False, False, True, False, False)
                    On Error GoTo 0
                Sheets("TrngRpt").Select
            Range("P3").Select
        Protect_All
    Exit Sub

errHandler:
    Protect_All
        MsgBox "No match found for " & txtRpt3.Text
    Exit Sub
End Sub

Sub AdvFilterPvt1()
' Pivot table 1
    Sheets("Data").Range("HistData4[#All]").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Sheet21.Range("K5:L6"), CopyToRange:=Sheet21.Range("PvtTblRS[#Headers]"), _
        Unique:=False
End Sub

Sub AdvFilterPvt2()
' Pivot table 2
    Sheets("Data").Range("HistData4[#All]").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Sheet21.Range("PvtSearch!Criteria"), CopyToRange:=Sheet21.Range( _
        "PvtTblRS28[#Headers]"), Unique:=False
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,214,611
Messages
6,120,513
Members
448,967
Latest member
screechyboy79

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