Hi, I copies a macro to filter/sort then copy, create worksheet, and then paste. I changed the descending to ascending in the second macro, that's it. Descending works fine, but can't figure out why second one (ascending) errors out with "Run-time error 91" "object variable or with block variable not set on "ActiveWorkbook.Worksheets("Questions").AutoFilter.Sort. _
SortFields.Clear" So, then I recorded the macro for ascending filter/sort and pasted that one, same error. My buddy who knows vba well took a look at it and couldn't figure it out. Help would be greatly appreciated
SortFields.Clear" So, then I recorded the macro for ascending filter/sort and pasted that one, same error. My buddy who knows vba well took a look at it and couldn't figure it out. Help would be greatly appreciated
Code:
'filter Descending
ActiveWorkbook.Sheets("Questions").Activate
With ActiveWorkbook.Sheets("Questions")
Range("G2:G60").Select
Selection.AutoFilter
ActiveWorkbook.Worksheets("Questions").AutoFilter.Sort. _
SortFields.Clear
ActiveWorkbook.Worksheets("Questions").AutoFilter.Sort. _
SortFields.Add Key:=Range("G2:G60"), SortOn:=xlSortOnValues, Order:= _
xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Questions").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Rows("3:60").Select
Selection.Copy
Worksheets.Add(After:=Worksheets("Slide 10")).Name = "Slide 11 "
Cells.Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
ActiveSheet.Paste
End With
'filter Ascending
ActiveWorkbook.Sheets("Questions").Activate
With ActiveWorkbook.Sheets("Questions")
Range("G2:G60").Select
Selection.AutoFilter
ActiveWorkbook.Worksheets("Questions").AutoFilter.Sort. _
SortFields.Clear
ActiveWorkbook.Worksheets("Questions").AutoFilter.Sort. _
SortFields.Add Key:=Range("G2:G60"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Questions").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Rows("3:60").Select
Selection.Copy
Worksheets.Add(After:=Worksheets("Slide 11")).Name = "Slide 12"
Cells.Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
ActiveSheet.Paste
end with