Sub CopyCols()
Application.ScreenUpdating = False
Dim SLIsh As Worksheet, SMIsh As Worksheet, DATAsh As Worksheet, MASTERsh As Worksheet
Set SLIsh = ThisWorkbook.Sheets("Sales lease invoice$")
Set SMIsh = ThisWorkbook.Sheets("Sales material invoice$")
Set DATAsh = Workbooks("Sales Report YTD.xlsx").Sheets("DATA")
Set MASTERsh = Workbooks("master.xlsx").Sheets("Sheet1")
SLIsh.UsedRange.Offset(1, 0).ClearContents
SMIsh.UsedRange.Offset(1, 0).ClearContents
Dim beginDate As String, endDate As String
Dim bottomA As Long, bottomB As Long, x As Long, lastRow As Long, bottomF As Long, total As Long
Dim des As Range, rngUniques As Range, inv As Range
x = 2
Dim WIP As Range
Dim ws As Worksheet
For Each ws In Sheets
If ws.Name = "Sales lease invoice$" Then
bottomA = MASTERsh.Range("A" & MASTERsh.Rows.Count).End(xlUp).Row
Intersect(MASTERsh.Rows("2:" & bottomA), MASTERsh.Range("D:D")).Copy ws.Cells(ws.Rows.Count, "A").End(xlUp).Offset(1, 0)
Intersect(MASTERsh.Rows("2:" & bottomA), MASTERsh.Range("G:G")).Copy ws.Cells(ws.Rows.Count, "E").End(xlUp).Offset(1, 0)
Intersect(MASTERsh.Rows("2:" & bottomA), MASTERsh.Range("H:I")).Copy ws.Cells(ws.Rows.Count, "C").End(xlUp).Offset(1, 0)
Intersect(MASTERsh.Rows("2:" & bottomA), MASTERsh.Range("J:K")).Copy ws.Cells(ws.Rows.Count, "Z").End(xlUp).Offset(1, 0)
Intersect(MASTERsh.Rows("2:" & bottomA), MASTERsh.Range("L:L")).Copy ws.Cells(ws.Rows.Count, "L").End(xlUp).Offset(1, 0)
Intersect(MASTERsh.Rows("2:" & bottomA), MASTERsh.Range("M:M")).Copy ws.Cells(ws.Rows.Count, "K").End(xlUp).Offset(1, 0)
Intersect(MASTERsh.Rows("2:" & bottomA), MASTERsh.Range("P:P")).Copy ws.Cells(ws.Rows.Count, "G").End(xlUp).Offset(1, 0)
ElseIf ws.Name = "Sales material invoice$" Then
bottomA = DATAsh.Range("A" & DATAsh.Rows.Count).End(xlUp).Row
DATAsh.Range("A1:A" & bottomA).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("A1:A" & bottomA), Unique:=True
Set rngUniques = DATAsh.Range("A2:A" & bottomA).SpecialCells(xlCellTypeVisible)
DATAsh.Range("A2:A" & bottomA).SpecialCells(xlCellTypeVisible).Copy ws.Cells(ws.Rows.Count, "A").End(xlUp).Offset(1, 0)
DATAsh.Range("B2:C" & bottomA).SpecialCells(xlCellTypeVisible).Copy ws.Cells(ws.Rows.Count, "E").End(xlUp).Offset(1, 0)
DATAsh.Range("L2:L" & bottomA).SpecialCells(xlCellTypeVisible).Copy ws.Cells(ws.Rows.Count, "K").End(xlUp).Offset(1, 0)
DATAsh.Range("P2:P" & bottomA).SpecialCells(xlCellTypeVisible).Copy ws.Cells(ws.Rows.Count, "Y").End(xlUp).Offset(1, 0)
DATAsh.Range("S2:S" & bottomA).SpecialCells(xlCellTypeVisible).Copy
ws.Cells(ws.Rows.Count, "L").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
If DATAsh.FilterMode Then DATAsh.ShowAllData
bottomF = SMIsh.Range("F" & SMIsh.Rows.Count).End(xlUp).Row
For Each des In SMIsh.Range("F4:F" & bottomF)
des = "PO" & des
Next des
For Each inv In rngUniques
DATAsh.Range("A1:S" & bottomA).AutoFilter Field:=1, Criteria1:=inv
ws.Cells(ws.Rows.Count, "G").End(xlUp).Offset(1, 0) = WorksheetFunction.Sum(DATAsh.Range("I2:I" & bottomA).SpecialCells(xlCellTypeVisible))
If DATAsh.FilterMode Then DATAsh.ShowAllData
Next inv
End If
Next ws
End Sub