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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

mville

New Member
Joined
Nov 3, 2011
Messages
36
I need to do it throught a macro...not throught data/sort.
How can I do it?
 

Kenneth Hobson

Well-known Member
Joined
Feb 6, 2007
Messages
3,181
Office Version
  1. 365
Platform
  1. Windows

L. Howard

Well-known Member
Joined
Oct 16, 2012
Messages
4,514
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
 

Forum statistics

Threads
1,186,146
Messages
5,956,195
Members
438,238
Latest member
a cow tent

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