steve the excel guy
Board Regular
- Joined
- Aug 28, 2007
- Messages
- 104
Ok, I want to be able to sort many rows (over 800) alphabetically where Column A is the header column. I recorded a small sample macro to get an idea of what the code looks like. There is no option to leave Column A open as a header so for example only, I highlighted B1:H1, then sorted, then B2:H2, then sorted. Below is what it looks like. I would actually want the entire row (minus A) to be sorted to around 800 rows.
I want to add some kind of loop in here.
I want to add some kind of loop in here.
Code:
Sub sort1()
'
' sort1 Macro
'
'
Range("B1:H1").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("B1:H1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("B1:H1")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
Range("B2:H2").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("B2:H2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("B2:H2")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
End Sub