Sub Demo1r2d2()
Const C = 32
Dim V, S As Boolean, Ra As Range, Ws As Worksheet, R&
ChDrive Path: ChDir Path
With Application
.Speech.Speak "Choose a daily invoices Excel workbook", True
.DisplayAlerts = False
.ScreenUpdating = False
Do
V = .GetOpenFilename("Daily Invoices workbook,*.xlsx"): If V = False Then Exit Do
With Workbooks.Open(V, 0).ActiveSheet.UsedRange.Columns
S = .Cells(1, 8) = "Invoice Number"
If S Then
.Item(8).AdvancedFilter 2, , .Cells(1, C), True
If Application.CountBlank(.Item(6)) Then
.Item(6).UnMerge
For Each Ra In .Item(6).SpecialCells(4).Areas: Ra(0).Copy Ra: Next
End If
.Item(6) = Application.IfError(Application.VLookup(.Item(6), Sheet2.UsedRange, 2, False), .Item(6))
.Item(6).AutoFit
Set Ws = Workbooks.Add(xlWBATWorksheet).ActiveSheet
ActiveWindow.DisplayWorkbookTabs = False
.Range("A1:G1").Copy
Ws.[A1].PasteSpecial 8
For R = 2 To .Cells(1, C).End(xlDown).Row
.AutoFilter 8, .Cells(R, C)
.Item("A:G").Copy Ws.[A1]
Ws.UsedRange.Columns(2).AutoFit
Ws.Parent.SaveAs Path & "\" & .Cells(R, C), 51
Ws.UsedRange.Clear
Next
Application.Speech.Speak "Done!", True
Ws.Parent.Close False
Set Ws = Nothing
.AutoFilter 8
.Item(C).Clear
Else
Application.Speech.Speak "Wrong file!", True, , True
End If
.Parent.Parent.Close S
End With
Loop Until S
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub