VBA sort worksheet by multiple columns using a previously created marco

fvisions

Board Regular
Joined
Jul 29, 2008
Messages
191
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: 6

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You are sorting on Col E then D not F then E.
 
Upvote 0
In that case, in what way isn't it working?
 
Upvote 0
And from your image it seems to be doing that.
 
Upvote 0
I can only think that you have other charachters in some or all of those cells, as the code works fine for me.
 
Upvote 0
I figured out my mistake. Thank you for looking at this with me.
 
Upvote 0

Forum statistics

Threads
1,213,539
Messages
6,114,221
Members
448,554
Latest member
Gleisner2

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