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