Sub vbax_51313_2014_req2019_Split_Monthly_Sales_2ws_To_Product_Worksheets()
Dim ProductNames As String, wsSales As String, LastDateInMonth As String
Dim Products, slsArr
Dim i As Long, LastRow As Long
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
For i = 1 To Worksheets.Count
If Worksheets(i).Name <> "SalesData1" And Worksheets(i).Name <> "SalesData2" Then
ProductNames = ProductNames & "|" & Worksheets(i).Name
End If
Next
Products = Split(Mid(ProductNames, 2), "|")
wsSales = Application.InputBox(Prompt:="Input the name of the worksheet which contains the sales data!", Type:=2)
LastDateInMonth = Application.InputBox(Prompt:="Enter Last Date of Month in 'MM/DD/YYYY' format Like 11/30/2014", Type:=2)
With Worksheets(wsSales)
.AutoFilterMode = False
.Cells(1).AutoFilter Field:=6, Operator:=xlFilterValues, Criteria2:=Array(1, LastDateInMonth)
For i = LBound(Products) To UBound(Products)
.Cells(1).AutoFilter Field:=1, Criteria1:="=*" & Products(i) & "*"
If .AutoFilter.Range.Rows.Count > 1 Then
.AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Copy .Cells(1, 100)
slsArr = .Cells(1, 100).CurrentRegion.Value
.Cells(1, 100).CurrentRegion.Clear
LastRow = Worksheets(Products(i)).Range("A" & Rows.Count).End(xlUp).Offset(1).Row
Worksheets(Products(i)).Cells(LastRow, 1).Resize(UBound(slsArr, 1), 1).Value = Application.Index(slsArr, , 1)
Worksheets(Products(i)).Cells(LastRow, 2).Resize(UBound(slsArr, 1), 1).Value = Application.Index(slsArr, , 2)
Worksheets(Products(i)).Cells(LastRow, 5).Resize(UBound(slsArr, 1), 1).Value = Application.Index(slsArr, , 3)
Worksheets(Products(i)).Cells(LastRow, 6).Resize(UBound(slsArr, 1), 1).Value = Application.Index(slsArr, , 4)
Worksheets(Products(i)).Cells(LastRow, 7).Resize(UBound(slsArr, 1), 1).Value = Application.Index(slsArr, , 5)
Worksheets(Products(i)).Cells(LastRow, 10).Resize(UBound(slsArr, 1), 1).Value = Application.Index(slsArr, , 6)
End If
Next i
.AutoFilterMode = False
End With
End Sub