PMRetired2012
Board Regular
- Joined
- Aug 6, 2019
- Messages
- 123
I think i have a problem but not sure. I am going to put a macro on here for someone to help me with. the problem is: When i am using F8 to step thur the macro and i am watching as i step thur the sheet and that sheet is named workers or Visitors the macro does just like it does on all the other ones. The first line of the macro as i have it written shows to ignoe the sheets Workers, Visitors. What happens it treats those two sheets just like the other sheets and that is: If im looking at one of the other sheets it will do the 2 part sort. A3:AM32 then it will do the second part of the sort A36:A39. then it goes to the bottom part of the macro and sorts the sheets if i am working on the sheets workers and visitors like i want it to do. So what im saying is that i want to macro to do when using the F8 step thru and the active sheet being Workers and Visitors is to not is to jump down and sort the sheet from the bottom part of the macro and to ignore those 2 sheets when my active sheet is one other than those two. I belive the main line of code messed up is the first one it wont ignore those
Sub SORTDATA()
'Sort Data on Seets PreK-Visitors
If ActiveWorkbook.ActiveSheet.Name <> "WORKERS" Or ActiveWorkbook.ActiveSheet.Name <> "VISITORS" Then
Range("A3:AM32").Select
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("A3:A32"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("A3:AM32")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Second Sort Starts here
Range("A36:AM39").Select
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("A36:A39"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("A36:AM39")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End If
If ActiveWorkbook.ActiveSheet.Name = "WORKERS" Or ActiveWorkbook.ActiveSheet.Name = "VISITORS" Then
Range("A3:AM39").Select
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("A3:A39"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("A3:AM39")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End If
Range("A3").Select
End Sub
Sub SORTDATA()
'Sort Data on Seets PreK-Visitors
If ActiveWorkbook.ActiveSheet.Name <> "WORKERS" Or ActiveWorkbook.ActiveSheet.Name <> "VISITORS" Then
Range("A3:AM32").Select
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("A3:A32"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("A3:AM32")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Second Sort Starts here
Range("A36:AM39").Select
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("A36:A39"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("A36:AM39")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End If
If ActiveWorkbook.ActiveSheet.Name = "WORKERS" Or ActiveWorkbook.ActiveSheet.Name = "VISITORS" Then
Range("A3:AM39").Select
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("A3:A39"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("A3:AM39")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End If
Range("A3").Select
End Sub