macro to sort in alphabetical order

mville

New Member
Joined
Nov 3, 2011
Messages
36
Hi,
I selected Range(A2:C500). Column A represents last names.
I want to sort that range based on alphabetical value from the last names in column A.
How can I do that?
Thanks
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Upvote 0
Here is a pretty simple example to sort with a macro.

Easy to change the range (oneRng) and the sort column (aCol) as needed.
This assumes you have headers for the names, Last, First, Middle... etc. or whatever.
There is no need to select the range of data on the sheet.

Howard


Code:
Option Explicit

Sub A_Macro_Sort()

Dim oneRng As Range
Dim aCol As Range

Set oneRng = Range("A1:C500")
Set aCol = Range("A1")

oneRng.Sort Key1:=aCol, Order1:=xlAscending, Header:=xlYes
'oneRng.Sort Key1:=aCol, Order1:=xlDescending, Header:=xlYes

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

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