Something wrong with file, dont know what so i create a new one, with small modification in code
Sub test()
Dim lr As Long, arr As Variant, x As Long
Application.ScreenUpdating = False
With Sheets("Request")
arr = .Range("A1", "C" & .Range("A" & .Rows.Count).End(xlUp).Row)
For x = 1 To UBound(arr)
If arr(x, 3) = "" Then arr(x, 3) = arr(x - 1, 3)
Next
End With
With Sheets("Sheet1")
colp = Application.Match("Product", .Range("1:1"), 0)
colc = Application.Match("Customer Code", .Range("1:1"), 0)
colt = Application.Match("Type", .Range("1:1"), 0)
If .AutoFilterMode Then .AutoFilter.ShowAllData
For x = 1 To UBound(arr)
Select Case arr(x, 3)
Case Is = "C"
.Range("A1").CurrentRegion.AutoFilter field:=colc, Criteria1:=arr(x, 1)
With .Range("A1").CurrentRegion
.Offset(1).Copy Sheets("Help").Range("A1")
End With
With Sheets("Help")
lr = .Range("A" & .Rows.Count).End(xlUp).Row
.Sort.SortFields.Add2 Key:=Range(Cells(1, colp), Cells(lr, colp)) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
End With
With Sheets("Help").Sort
.SetRange Range("A1").CurrentRegion
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Help").Copy
ActiveWorkbook.SaveAs arr(x, 2) & "\" & Range("A1").Value & ".xlsx"
ActiveWorkbook.Close True
Sheets("Help").Range("A1").CurrentRegion.ClearContents
Case Is = "P"
.Range("A1").CurrentRegion.AutoFilter field:=colp, Criteria1:=arr(x, 1)
With .Range("A1").CurrentRegion
.Offset(1).Copy Sheets("Help").Range("A1")
End With
With Sheets("Help")
lr = .Range("A" & .Rows.Count).End(xlUp).Row
.Sort.SortFields.Add2 Key:=Range(Cells(1, colc), Cells(lr, colc)) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
End With
With Sheets("Help").Sort
.SetRange Range("A1").CurrentRegion
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Help").Copy
ActiveWorkbook.SaveAs arr(x, 2) & "\" & Range("B1").Value & ".xlsx"
ActiveWorkbook.Close True
Sheets("Help").Range("A1").CurrentRegion.ClearContents
Case Is = "T"
.Range("A1").CurrentRegion.AutoFilter field:=colt, Criteria1:=arr(x, 1)
With .Range("A1").CurrentRegion
.Offset(1).Copy Sheets("Help").Range("A1")
End With
With Sheets("Help")
lr = .Range("A" & .Rows.Count).End(xlUp).Row
.Sort.SortFields.Add2 Key:=Range(Cells(1, colc), Cells(lr, colc)) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add2 Key:=Range(Cells(1, colp), Cells(lr, colp)) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
End With
With Sheets("Help").Sort
.SetRange Range("A1").CurrentRegion
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Help").Copy
ActiveWorkbook.SaveAs arr(x, 2) & "\" & Range("C1").Value & ".xlsx"
ActiveWorkbook.Close True
Sheets("Help").Range("A1").CurrentRegion.ClearContents
End Select
.AutoFilter.ShowAllData
Next
End With
End Sub
Bookmarks