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.
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