Alphabetical Order Macro [VBA/Excel]
Solved
styvea
Posted messages
36
Status
Member
-
styvea Posted messages 36 Status Member -
styvea Posted messages 36 Status Member -
Hello,
I would like to know if there is a macro in Excel that can sort a table alphabetically based on a specific column, please.
I tried using "record a macro" and doing it with the mouse, but I don't see what to change to get what I want.
Here is the code I got:
Mars being the name of the current sheet, but since the sheet can change at any time, I would need something like ActiveSheets. And since the size of the table is variable, I need a Range that selects the entire table on the page.
I tried this code:
But it doesn't work and I can't really see where the error is...
Thanks to anyone who can help :) Best regards
StyveA
Configuration: Windows 7 / Internet Explorer 8.0
I would like to know if there is a macro in Excel that can sort a table alphabetically based on a specific column, please.
I tried using "record a macro" and doing it with the mouse, but I don't see what to change to get what I want.
Here is the code I got:
Sub ordre_alpha() ' ' ordre_alpha Macro ' ' Range("A1:K18").Select ActiveWorkbook.Worksheets("Mars").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Mars").Sort.SortFields.Add Key:=Range("B2:B18"), _ SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("Mars").Sort .SetRange Range("A1:K18") .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End Sub Mars being the name of the current sheet, but since the sheet can change at any time, I would need something like ActiveSheets. And since the size of the table is variable, I need a Range that selects the entire table on the page.
I tried this code:
Sub Macro3() ' ' Macro3 Macro ' ' nbc = UsedRange.Columns.Count nbl = UsedRange.Rows.Count UsedRange.Columns.Count.Select ActiveWorkbook.ActiveSheet.Sort.sortfiels.Clear ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("B2:nbl"), _ SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets.ActiveSheet.Sort .SetRange Range("nbl:nbc") .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End Sub But it doesn't work and I can't really see where the error is...
Thanks to anyone who can help :) Best regards
StyveA
Configuration: Windows 7 / Internet Explorer 8.0
Thank you very much, I'll try that right away!
(I suppose it'll work on the current sheet?