AutoFilter method of Range class failed error

di70910

New Member
Joined
May 6, 2022
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
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
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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