Macro Sort Columns by Row

jmmcq908

New Member
Joined
Jul 21, 2011
Messages
1
Hey I am having trouble with this macro I recorded. I selected columns D through AK and then sorted by row 1. When I run the macro it dosnt sort by row 1. It just highlights the columns that I highlighted before.

Here is my code for the macro:


Sub Macro2()
'
' Macro2 Macro
'
'
Columns("D:AK").Select
ActiveWorkbook.Worksheets("ROW TEMPLATE (3)").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("ROW TEMPLATE (3)").Sort.SortFields.Add Key:=Range( _
"D1:AK1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("ROW TEMPLATE (3)").Sort
.SetRange Range("D1:AK20")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Instead of writing the macro I suggest you RECORD a macro taking the successive steps for sorting and then edit the macro recorded.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

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