Sort macro

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
261
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
 

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
261
Glad it's sorted & thanks for the feedback.
I meant when I manually format it to number it works as a test. But I don't want to have to do that. I was hoping the macro can change the format to number.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,614
Office Version
  1. 365
Platform
  1. Windows
Simply changing the format of a cell should not make any difference, as it does not change the underlying value.
 

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
261
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



 

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
261
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?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,614
Office Version
  1. 365
Platform
  1. Windows
The best way is to convert your numbers into real numbers, it can save you a lot of problems.
 

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
261
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
 

Watch MrExcel Video

Forum statistics

Threads
1,129,685
Messages
5,637,798
Members
416,983
Latest member
LessThanAverageUser

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