I'm having trouble creating a macro to sort my worksheets based on a column/row1 header name. The name im trying to search for is NAME and then sort to a-z.
I recorded a macro but the issue i'm haivng is the word NAME can be in any column its not always in the same column but it will always be in row 1 and i also need this to apply to multiple worksheets.
Sub Macro1()
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("F2:F328") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1:Y328")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Bookmarks