I keep getting AutoFilter method of Range class failed message. I'm following a tutorial online and I did everything as it's mentioned there but I just can't understand what I wrote wrong in this part. Any help?
Sub Show_Sale_Purchase_Data()
Dim dsh As Worksheet
Dim sh As Worksheet
Set dsh = ThisWorkbook.Sheets("Sale_Purchase")
Set dsh = ThisWorkbook.Sheets("Sale_Purchase_Display")
dsh.AutoFilterMode = False
dsh.Range("H:H").NumberFormat = "D-MMM-YYYY"
''''''' Put filter here
dsh.UsedRange.AutoFilter 8, ">=" & Me.txt_Start_Date.Value, xlAnd, "<=" & Me.txt_End_Date.Value
If Me.OptionButton2.Value = True Then
dsh.UsedRange.AutoFilter 3, "Purchase"
End If
If Me.OptionButton3.Value = True Then
dsh.UsedRange.AutoFilter 3, "Sale"
End If
sh.UsedRange.Clear
dsh.UsedRange.Copy
sh.Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
''''''' display data in listbox
Dim lr As Long
lr = Application.WorksheetFunction.CountA(sh.Range("A:A"))
If lr = 1 Then lr = 2
With Me.ListBox2
.ColumnCount = 8
.ColumnHeads = True
.ColumnWidths = "0,120,70,70,70,70,70,70"
.RowSource = sh.Name & "!A2:H" & lr
End With
Sub Show_Sale_Purchase_Data()
Dim dsh As Worksheet
Dim sh As Worksheet
Set dsh = ThisWorkbook.Sheets("Sale_Purchase")
Set dsh = ThisWorkbook.Sheets("Sale_Purchase_Display")
dsh.AutoFilterMode = False
dsh.Range("H:H").NumberFormat = "D-MMM-YYYY"
''''''' Put filter here
dsh.UsedRange.AutoFilter 8, ">=" & Me.txt_Start_Date.Value, xlAnd, "<=" & Me.txt_End_Date.Value
If Me.OptionButton2.Value = True Then
dsh.UsedRange.AutoFilter 3, "Purchase"
End If
If Me.OptionButton3.Value = True Then
dsh.UsedRange.AutoFilter 3, "Sale"
End If
sh.UsedRange.Clear
dsh.UsedRange.Copy
sh.Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
''''''' display data in listbox
Dim lr As Long
lr = Application.WorksheetFunction.CountA(sh.Range("A:A"))
If lr = 1 Then lr = 2
With Me.ListBox2
.ColumnCount = 8
.ColumnHeads = True
.ColumnWidths = "0,120,70,70,70,70,70,70"
.RowSource = sh.Name & "!A2:H" & lr
End With