Sort macro

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
365
Hi, I recorded the macro to sort a range starting at A3 to column D, down to last row. I want to sort ascending in column C and then D. I changed the key:=Range("C3:C100" _ in line 6 & 8 to key:=Range("C3" _, and it seemed to work. However, I dont know what to do with the this on line 11: .SetRange Range("A3:D100") to not limit at 100. Thanks

VBA Code:
Sub SORT_TOT_FAB()
Application.ScreenUpdating = False
Range("A3:D3").Select
    Range(Selection, Selection.End(xlDown)).Select
    ActiveWorkbook.Worksheets("TOT FAB").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("TOT FAB").Sort.SortFields.Add2 key:=Range("C3:C100" _
        ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("TOT FAB").Sort.SortFields.Add2 key:=Range("D3:D100" _
        ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("TOT FAB").Sort
        .SetRange Range("A3:D100")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("E3").Select
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Simply changing the format of a cell should not make any difference, as it does not change the underlying value.
 
Upvote 0
Simply changing the format of a cell should not make any difference, as it does not change the underlying value.
OK,so maybe I'm asking the wrong questions. Is there a way to have sample A result in sample B?

sample A
19
21
23
66
8

Sample B
8
19
21
23
66



 
Upvote 0
Simply changing the format of a cell should not make any difference, as it does not change the underlying value.
I just realized what you mean it has nothing to do with the format. But when I sort the data using "data / sort" from the ribbon, it sorts the way I want. But the way it sorts in macro is different?
 
Upvote 0
The best way is to convert your numbers into real numbers, it can save you a lot of problems.
 
Upvote 0
Simply changing the format of a cell should not make any difference, as it does not change the underlying value.
Fluff, disregard all my recent posts...I had my sort macro disabled so it wasn't really sorting. Sorry to waste your time. It's working correctly. Thanks
 
Upvote 0

Forum statistics

Threads
1,214,403
Messages
6,119,308
Members
448,886
Latest member
GBCTeacher

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