Hi All - I have below code which loops an array (filters column A) to create a report per business. However, I am encountering an error everytime my arr is just 1 business. Can you help me modify below code which will proceed even though there is just 1 business in column A? Thank you!
Code:
For i = 1 To UBound(MyArr) 'loop through array values one at a time
'Filter column A by the current value
Range("A:A").AutoFilter Field:=1, Criteria1:=MyArr(i)
'Create a new blank sheet named for the current array value
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = MyArr(i)
ws.Activate
'Copy current filtered rows to new sheet, values only and formatting preserved
Range("B1:W" & LR).EntireColumn.Copy
Sheets(MyArr(i)).Range("A1").PasteSpecial xlPasteValues
Sheets(MyArr(i)).Range("A1").PasteSpecial xlPasteFormats
'Count how many rows were moved for message later
MyCount = MyCount + Sheets(MyArr(i)).Range("A" & Rows.Count).End(xlUp).Row - 1
'Tighten up appearance
Sheets(MyArr(i)).Columns.AutoFit
'Move new sheet to workbook of its own
Sheets(MyArr(i)).Move
Call CreatePivots
'Save new workbook with array value as name, then close
ActiveWorkbook.SaveAs FolderName2 & "WD 5 Actual Line Items_" & MyArr(i) & ".xlsx"
ActiveWorkbook.Close False
'reset the autofilter
Range("A:A").AutoFilter Field:=1
'End If
PctDone = i / UBound(MyArr)
UpdateProgressBar PctDone
Next i 'Loop to next array value