Good afternoon,
This is my first post here, but I have relied upon this forum for solutions to several other problems. So, gratitude is due for your indirect help on prior issues. Now hopefully you can help me directly with my current issue.
I have a spreasheet and macro which takes bulk data, filters it and pastes it into different tabs based on category, and then subtotals that data before copying and pasting all of the subtotals onto another sheet. The problem I am having is that occasionally there is no data within a certain category, so the correponding sheet will be blank (except for headers). When the macro runs, I get a "run-time error '1004'" when it attempts to sub-total the data on the blank sheet. Is there a way to skip this step of the macro if there is no data within a certain sheet/range?
If it helps, here is the portion of VBA language where it hangs-up:
Sheets("Outsource AA").Select
Columns("A:A").Select
ActiveWorkbook.Worksheets("Outsource AA").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Outsource AA").Sort.SortFields.Add Key:=Range("A1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Outsource AA").Sort
.SetRange Range("A2:I999")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 4), Array(10, 1)), TrailingMinusNumbers:=True
Range("A1").Select
ActiveCell.FormulaR1C1 = "Date"
Columns("A:A").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.ColumnWidth = 13
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Range("D13").Select
ActiveWindow.SmallScroll Down:=-15
Columns("A:A").Select
Selection.Subtotal GroupBy:=1, Function:=xlCount, TotalList:=Array(1), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=False
Range("C13").Select
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 2), Array(9, 1)), TrailingMinusNumbers:=True
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Bookmarks