Macro to filter according to selection works in normal list but not with defined table

Yamezz

Active Member
Joined
Nov 22, 2006
Messages
329
Office Version
  1. 2019
I have the macro below that works fine with a list of entries, but when I try to run it on a defined table I get the following error:
Run-time error '1004':
Autofilter method of Range class failed

Why do I encounter the discrepancy?

VBA Code:
Sub FilterBySelection()

If ActiveCell.Value = "" Then Exit Sub

  Dim fc As Long, cols As Long
  Dim c As Range
  
  With ActiveSheet
    With .UsedRange.Offset(1)
      fc = .Column
      For Each c In Selection
        .AutoFilter Field:=c.Column - fc + 1, Criteria1:=c.Value
      Next c
    End With
  End With
  
Range("A1").Activate
Application.GoTo ActiveCell, True

End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,214,840
Messages
6,121,895
Members
449,058
Latest member
Guy Boot

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