VBA sort worksheet by multiple columns using a previously created marco

fvisions

Board Regular
Joined
Jul 29, 2008
Messages
184
Office Version
  1. 365
Platform
  1. Windows
I created a marco and tried to copy it into an existing VBA code to sort a worksheet by column F then E Ascending but it does not appear to be working.

1604681585438.png

VBA Code:
With ActiveWorkbook.Worksheets("Municipal Purchase").Sort
   ActiveWorkbook.Worksheets("Municipal Purchase").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Municipal Purchase").Sort.SortFields.Add Key:=Range( _
        "E2:E" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortTextAsNumbers
    ActiveWorkbook.Worksheets("Municipal Purchase").Sort.SortFields.Add Key:=Range( _
        "D2:D" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets("Municipal Purchase").Sort
        .SetRange Range("A1:AZ" & LastRow)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
        
     End With
 

Attachments

  • 1604681571193.png
    1604681571193.png
    5.1 KB · Views: 4

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,526
Office Version
  1. 365
Platform
  1. Windows
Glad you sorted it & thanks for the feedback.
 

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

fvisions

Board Regular
Joined
Jul 29, 2008
Messages
184
Office Version
  1. 365
Platform
  1. Windows
Please disregard. I have the vba working correctly
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,526
Office Version
  1. 365
Platform
  1. Windows
Glad you sorted it & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,529
Messages
5,625,351
Members
416,096
Latest member
forevans

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
Top