this code seem to work only when the active worksheet is labelled as "analysis 1"
I have commented the working part and write my own code in order to try and make the code to run on any active worksheet on this work book this is the line that has an error but also see the screen shot
ActiveWorkbook.Worksheets("Analysis 1")
i tried to use activeWorksheet method i also tried using dim ws as worksheet ActiveWorkbook.activeWorksheet(ws.name).sort.. i tried using a for loop as well please see below code
Sub sortColumns()
'
' sortColumns Macro
'
For Each s In ActiveWorkbook.Sheets
'
'ActiveWorkbook.Worksheets("Analysis 1").Sort.SortFields.Clear
' Dim ws As Worksheet
'ActiveWorkbook.Worksheets("Analysis 1").Sort.SortFields.Add2 Key:=Range( _
"G5:G781951"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.s.Sort.SortFields.Clear
ActiveWorkbook.s.Sort.SortFields.Add2 Key:=Range( _
"G5:G781951"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.s.Sort
.SetRange Range("A4:H781951")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Next s
End Sub
Sort All Worksheets