Module1 - 1
Sub Clean_Up_Report()
Dim SourceLastRow As Long
Dim SourceLastRow1 As Long
Dim SourceLastRow2 As Long
Dim SourceLastRow3 As Long
Dim SourceLastRow4 As Long
Dim OutputLastRow As Long
Dim SourceLastColumn As Long
Dim SourceLastColumn1 As Long
Dim SourceLastColumn2 As Long
Dim SourceLastColumn3 As Long
Dim SourceLastColumn4 As Long
Dim sourceSheet As Worksheet
Dim sourceSheet1 As Worksheet
Dim sourceSheet2 As Worksheet
Dim sourceSheet3 As Worksheet
Dim sourceSheet4 As Worksheet
Dim outputSheet As Worksheet
Set sourceSheet = Worksheets("iTrade Report")
Set sourceSheet1 = Worksheets("MSR")
Set sourceSheet2 = Worksheets("FromTo")
Set sourceSheet3 = Worksheets("Sysco OG")
Set sourceSheet4 = Worksheets("Sysco Stock Matrix")
Set outputSheet = Worksheets("Clean Up")
With sourceSheet
SourceLastRow = .Cells(.[Link], "K").End(xlUp).Row
End With
With sourceSheet
SourceLastColumn = .Cells(.[Link], "K").End(xlUp).Column
End With
With sourceSheet1
SourceLastRow1 = .Cells(.[Link], "J").End(xlUp).Row
End With
With sourceSheet1
SourceLastColumn1 = .Cells(.[Link], "J").End(xlUp).Column
End With
With sourceSheet2
SourceLastRow2 = .Cells(.[Link], "A").End(xlUp).Row
End With
With sourceSheet2
SourceLastColumn2 = .Cells(.[Link], "A").End(xlUp).Column
End With
With sourceSheet3
SourceLastRow3 = .Cells(.[Link], "A").End(xlUp).Row
End With
With sourceSheet3
SourceLastColumn3 = .Cells(.[Link], "A").End(xlUp).Column
End With
With sourceSheet4
SourceLastRow4 = .Cells(.[Link], "A").End(xlUp).Row
End With
With sourceSheet4
SourceLastColumn4 = .Cells(.[Link], "A").End(xlUp).Column
End With
Module1 - 2
'Copy Product Number, Product Name, Pack Size, and Description
LastRow = [Link]([Link], 3).End(xlUp).Row
[Link]("E13:H13", "E" & LastRow).Copy
[Link]("F12").PasteSpecial xlPasteValues
[Link]
'Copies DC Number, DC Name, and Decentralized National ID Number
LastRow = [Link]([Link], 3).End(xlUp).Row
[Link]("A13:C13", "A" & LastRow).Copy
[Link]("A12:C12").PasteSpecial xlPasteValues
[Link]
'DC Name on iTrade Report
With sourceSheet
SourceLastRow = .Cells(.[Link], "M").End(xlUp).Row
.Range("O2:O" & SourceLastRow).Formula = _
"=SUBSTITUTE($M2,""SYSCO "","""")"
End With
'Define Number of months on MSR
With sourceSheet1
SourceLastRow1 = .Cells(.[Link], "A").End(xlUp).Row
.Range("K2").Formula = _
"=SUMPRODUCT((D12:D100000 <> """")/COUNTIF(D12:D100000,D12:D100000 & """"))"
.Range("K2").[Link] = vbWhite
End With
'Populate Sector on CleanUp Sheet
'Part I
With outputSheet
OutputLastRow = .Cells([Link], "A").End(xlUp).Row
.Range("AY12:AY" & OutputLastRow).Formula = _
"=IFERROR(INDEX($AZ$12:$AZ$17,AGGREGATE(15,6,MATCH(""*""&$AZ$12:$AZ$17&""*"",$C12,0)*(ROW($AZ$
12:$AZ$17)-ROW(AZ$12)+1),1)),"""")"
End With
'Part II
With outputSheet
OutputLastRow = .Cells([Link], "A").End(xlUp).Row
.Range("D12:D" & OutputLastRow).Formula = _
"=IF($AY12=$AZ$12,$BA$12,IF($AY12=$AZ$13,$BA$13,IF($AY12=$AZ$14,$BA$14,IF($AY12=$AZ$15,$BA$15,
IF($AY12=$AZ$16,$BA$16,IF($AY12=$AZ$17,$BA$17,""""))))))"
End With
'Fill in Order Guide Type
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("E12:E" & OutputLastRow).Formula = _
"=IF($D12=$BA$12,$BB$12,IF($D12=$BA$13,$BB$13,IF($D12=$BA$14,$BB$14,IF($D12=$BA$15,$BB$15,IF($
D12=$BA$16,"""",IF($D12=$BA$17,$BB$17,""""))))))"
End With
'MONTHLY SUMMARIES
'Sum for Month of January
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("J12:J" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & [Link] & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
[Link] & "'!D$13:D$" & SourceLastRow1 & "=$J$10)*('" & [Link] & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & [Link] & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & [Link]
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Sum for Month of February
With outputSheet
Module1 - 3
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("K12:K" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & [Link] & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
[Link] & "'!D$13:D$" & SourceLastRow1 & "=$K$10)*('" & [Link] & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & [Link] & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & [Link]
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Sum for Month of March
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("L12:L" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & [Link] & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
[Link] & "'!D$13:D$" & SourceLastRow1 & "=$L$10)*('" & [Link] & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & [Link] & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & [Link]
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Sum for Month of April
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("M12:M" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & [Link] & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
[Link] & "'!D$13:D$" & SourceLastRow1 & "=$M$10)*('" & [Link] & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & [Link] & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & [Link]
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Sum for Month of May
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("N12:N" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & [Link] & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
[Link] & "'!D$13:D$" & SourceLastRow1 & "=$N$10)*('" & [Link] & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & [Link] & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & [Link]
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Sum for Month of June
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("O12:O" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & [Link] & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
[Link] & "'!D$13:D$" & SourceLastRow1 & "=$O$10)*('" & [Link] & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & [Link] & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & [Link]
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Sum for Month of July
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("P12:P" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & [Link] & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
[Link] & "'!D$13:D$" & SourceLastRow1 & "=$P$10)*('" & [Link] & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & [Link] & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & [Link]
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Sum for Month of August
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("Q12:Q" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & [Link] & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
[Link] & "'!D$13:D$" & SourceLastRow1 & "=$Q$10)*('" & [Link] & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & [Link] & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & [Link]
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Sum for Month of September
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("R12:R" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & [Link] & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
[Link] & "'!D$13:D$" & SourceLastRow1 & "=$R$10)*('" & [Link] & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & [Link] & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & [Link]
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Sum for Month of October
Module1 - 4
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("S12:S" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & [Link] & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
[Link] & "'!D$13:D$" & SourceLastRow1 & "=$S$10)*('" & [Link] & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & [Link] & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & [Link]
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Sum for Month of November
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("T12:T" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & [Link] & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
[Link] & "'!D$13:D$" & SourceLastRow1 & "=$T$10)*('" & [Link] & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & [Link] & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & [Link]
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Sum for Month of December
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("U12:U" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & [Link] & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
[Link] & "'!D$13:D$" & SourceLastRow1 & "=$U$10)*('" & [Link] & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & [Link] & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & [Link]
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Eliminate Duplicate Rows
Dim MyRange As Range
LastRow = [Link]("F" & [Link]).End(xlUp).Row
Set MyRange = [Link]("A11:AE" & LastRow)
[Link] Columns:=Array(2, 3, 4, 6), Header:=xlYes
Range("D:D,J:X").[Link] = xlCenter
'Border Around Case Quantity Sum
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("V12:V" & OutputLastRow).Borders(xlEdgeLeft).Weight = xlMedium
.Range("V12:V" & OutputLastRow).Borders(xlEdgeRight).Weight = xlMedium
End With
'Border Separating Old from New
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("X12:X" & OutputLastRow).Borders(xlEdgeLeft).Weight = xlThick
End With
'New Product Information
'FORMAT "FROM TO" SHEET AS TEXT
Dim rng As Range: Set rng = [Link]("A1:H1000").CurrentRegion
Dim cCell As Range
For Each cCell In [Link]
If IsNumeric([Link]) Then
[Link] = "'" & CStr([Link])
End If
Next cCell
'FromTo Product Number
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("Z12:Z" & OutputLastRow).Formula = _
"=IFERROR(INDEX('" & [Link] & "'!F$3:F$" & SourceLastRow2 & ",MATCH(1,INDEX(($F
12='" & [Link] & "'!A$3:A$" & SourceLastRow2 & ")*($I12='" & [Link] & "'!D$3:D$"
& SourceLastRow2 & "),0,1),0),1),INDEX('" & [Link] & "'!F$3:F$" & SourceLastRow2 & ",MATCH
($F12,'" & [Link] & "'!F$3:F$" & SourceLastRow2 & ",0)))"
End With
Module1 - 5
'FromTo Product Description
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("AA12:AA" & OutputLastRow).Formula = _
"=IFERROR(VLOOKUP(F12,'" & [Link] & "'!$A$3:$I$" & SourceLastRow2 & ",7,FALSE),
INDEX('" & [Link] & "'!$G$3:$G$" & SourceLastRow2 & ",MATCH($F12,'" & [Link] & "
'!$F$3:$F$" & SourceLastRow2 & ",0)))"
End With
'FromTo Brand ID
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("AC12:AC" & OutputLastRow).Formula = _
"=VLOOKUP(Z12,'" & [Link] & "'!$F$3:$I$" & SourceLastRow2 & ",3,FALSE)"
End With
'Proprietary Status
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("AE12:AE" & OutputLastRow).Formula = _
"=VLOOKUP(F12,'" & [Link] & "'!$C$2:$K$" & SourceLastRow3 & ",9,FALSE)"
End With
'Sector
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("X12:X" & OutputLastRow).Formula = _
"=IF($D12="""","""",$D12)"
End With
'Order Guide
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("Y12:Y" & OutputLastRow).Formula = _
"=IF($E12="""","""",$E12)"
End With
'Stocking Status
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("AD12:AD" & OutputLastRow).Formula = _
"=INDEX('" & [Link] & "'!I$2:I$" & SourceLastRow4 & ",MATCH(1,INDEX((A12='" & sourc
[Link] & "'!A$2:A$" & SourceLastRow4 & ")*(Z12='" & [Link] & "'!B$2:B$" & SourceLastR
ow4 & "),0,1),0),1)"
End With
'Pack / Size
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("AB12:AB" & OutputLastRow).Formula = _
"=IFERROR(VLOOKUP(Z12,'" & [Link] & "'!$E$3:$G$" & SourceLastRow1 & ",3,FALSE),""""
)"
End With
'Format Entire Worksheet as "General"
[Link] = "General"
'Calculation Formulas
'Sum Case Quantity
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
.Range("V12:V" & OutputLastRow).Formula = _
"=IF(SUM($J12:$U12)="""","""",SUM($J12:$U12))"
End With
'Average Case Quantity
With outputSheet
OutputLastRow = .Cells(.[Link], "F").End(xlUp).Row
Module1 - 6
.Range("W12:W" & OutputLastRow).Formula = _
"=IF($V12/'" & [Link] & "'!$K$2>1,$V12/'" & [Link] & "'!$K$2,""Less
Than 1"")"
.Range("W12:W" & OutputLastRow).NumberFormat = "####"
'IF($V12/'" & [Link] & "'!$K$2>1,$V12/'" & [Link] & "'!$K$2,"Less Th
an 1")
End With
End Sub