How would I create a macro to sort each row alphabetically?

JonnyEnglish89

New Member
Joined
Jan 29, 2016
Messages
10
A
B
C
D
E
F
1
Kylen
Petrisis
Nexor
Silus the Corrupt
Krellus
Conqueror Krellus
2
Constantine
Barracus
Kylen
Daedalus
Elder Constantine
3
Dracorex
Constantine
Daedalus Enraged
Kylen
Nexor
Typhon Vex

<tbody>
</tbody>

I recorded a macro whilst using the custom sort feature in excel but I couldn’t figure out how to modify the recording to iterate though the rows
Any help would be appreciated
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Leith Ross

Well-known Member
Joined
Mar 17, 2008
Messages
1,874
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
Hello JonnyEnglish,

Do you want to sort a single column of your choice or all columns at once?
 
Upvote 0

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
This code sorts EACH ROW:-

Code:
[COLOR="Navy"]Sub[/COLOR] MG24Nov42
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, RngAc [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = Range("A2", Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]Set[/COLOR] RngAc = Range(Cells(Dn.Row, 1), Cells(Dn.Row, Columns.Count).End(xlToLeft))
    RngAc.Sort RngAc(1), xlAscending, Orientation:=xlLeftToRight
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,195,590
Messages
6,010,611
Members
441,558
Latest member
lambierules

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