Autofilter issue

Vbanoob98

Board Regular
Joined
Sep 13, 2019
Messages
128
I am trying to rewrite this code to work on a table imported from Power Query:
*The bold text is where its failing, I guess to not using a range, but I am unable to understand what .Cells.Autofilter is even doing

VBA Code:
Dim wsSrc As Worksheet

With wsSrc
            If .FilterMode Then .ShowAllData
            If .AutoFilterMode = False Then .Cells.AutoFilter   'This line is where its having the error
            Select Case .CodeName
                Case "Tool1", "Tool2", "Tool3", "Tool4", "Tool5"
                    lngSortCount = 1
                Case Else
                    lngSortCount = 2
            End Select
            If .CodeName <> "Summary" Then
                If .FilterMode Then .ShowAllData
                For i = 1 To lngSortCount
                    .AutoFilter.Sort.SortFields.Clear
                    Select Case .CodeName
                        Case "Tool6"
                            Set rngWorking = .Columns(2 * i).EntireColumn
                        Case "Tool2", "Tool3", "Tool4", "Tool5"
                            Set rngWorking = .Columns(2).EntireColumn
                        Case "Tool7"
                            Set rngWorking = .Columns(1).EntireColumn
                        Case Else
                            Set rngWorking = .Columns(i + 1).EntireColumn
                    End Select
                
                    .AutoFilter.Sort.SortFields.Add Key:=rngWorking, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
                        xlSortNormal
                    With .AutoFilter.Sort
                        .Header = xlYes
                        .MatchCase = False
                        .Orientation = xlTopToBottom
                        .SortMethod = xlPinYin
                        .Apply
                    End With
                Next i
            End If
            .Range(.Cells(1, 1), .Cells.SpecialCells(xlCellTypeLastCell)).Copy
        End With

Appreciate any help
 
Last edited:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,223,268
Messages
6,171,099
Members
452,379
Latest member
IainTru

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