VBA Variable Range Sort

GedSalter

Board Regular
Joined
Apr 24, 2019
Messages
80
Hi

I have a sheet I wish to sort depending on data in two columns. The table is a variable rows and I wish to sort with "Members" then "Social Members" I have got it to work on a previous version but took a long time to run. I am now trying the variable approach to see if its quicker.


VBA Code:
Private Sub CommandButton2_Click()

lr = Cells(Rows, Count, 1).End(xlUp).Row


 ActiveSheet.Range("$G$1").Value = "Social Members List"
 
ActiveWorkbook.Worksheets("Portal").ListObjects("Table5").Range.AutoFilter Field:=1 & lr
ActiveWorkbook.Worksheets("Portal").ListObjects("Table5").Range.AutoFilter Field:=3 & lr
ActiveWorkbook.Worksheets("Portal").ListObjects("Table5").Range.AutoFilter Field:=4 & lr
ActiveWorkbook.Worksheets("Portal").ListObjects("Table5").Range.AutoFilter Field:=5 & lr
ActiveWorkbook.Worksheets("Portal").ListObjects("Table5").Range.AutoFilter Field:=6 & lr
ActiveWorkbook.Worksheets("Portal").ListObjects("Table5").Range.AutoFilter Field:=7 & lr
ActiveWorkbook.Worksheets("Portal").ListObjects("Table5").Range.AutoFilter Field:=8 & lr
ActiveWorkbook.Worksheets("Portal").ListObjects("Table5").Range.AutoFilter Field:=9 & lr
ActiveWorkbook.Worksheets("Portal").ListObjects("Table5").Range.AutoFilter Field:=10 & lr

    ActiveWorkbook.Worksheets("Portal").ListObjects("Table5").Range.AutoFilter Field:=11, Criteria1:="Member" & lr

 ActiveWorkbook.Worksheets("Portal").ListObjects("Table5").Range.AutoFilter Field:=2, Criteria1:="Social" & lr

        
        Sheets("Portal").Select
        
    Range("A7").Select

        
Range("A7").Activate

End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I'm confused, you talk about sorting on two columns, but there is noting your code that sorts the table.
It looks more as though you are trying to clear all filters & then filter on 2 columns.
Can you please explain?
 
Upvote 0

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

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