Professional Documents
Culture Documents
Microsoft Visual Basic For Applications
Microsoft Visual Basic For Applications
Microsoft Visual Basic For Applications
Sub Clean_Up_Report()
With sourceSheet
SourceLastRow = .Cells(.Rows.Count, "K").End(xlUp).Row
End With
With sourceSheet
SourceLastColumn = .Cells(.Columns.Count, "K").End(xlUp).Column
End With
With sourceSheet1
SourceLastRow1 = .Cells(.Rows.Count, "J").End(xlUp).Row
End With
With sourceSheet1
SourceLastColumn1 = .Cells(.Columns.Count, "J").End(xlUp).Column
End With
With sourceSheet2
SourceLastRow2 = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
With sourceSheet2
SourceLastColumn2 = .Cells(.Columns.Count, "A").End(xlUp).Column
End With
With sourceSheet3
SourceLastRow3 = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
With sourceSheet3
SourceLastColumn3 = .Cells(.Columns.Count, "A").End(xlUp).Column
End With
With sourceSheet4
SourceLastRow4 = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
With sourceSheet4
SourceLastColumn4 = .Cells(.Columns.Count, "A").End(xlUp).Column
End With
Module1 - 2
'Part II
With outputSheet
OutputLastRow = .Cells(Rows.Count, "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
'MONTHLY SUMMARIES
Module1 - 3
End With
'Sum for Month of September
With outputSheet
OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("R12:R" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & sourceSheet1.Name & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
et1.Name & "'!D$13:D$" & SourceLastRow1 & "=$R$10)*('" & sourceSheet1.Name & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & sourceSheet1.Name & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & sourceSheet1.Name
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Sum for Month of October
With outputSheet
OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("S12:S" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & sourceSheet1.Name & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
et1.Name & "'!D$13:D$" & SourceLastRow1 & "=$S$10)*('" & sourceSheet1.Name & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & sourceSheet1.Name & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & sourceSheet1.Name
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Sum for Month of November
With outputSheet
OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("T12:T" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & sourceSheet1.Name & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
et1.Name & "'!D$13:D$" & SourceLastRow1 & "=$T$10)*('" & sourceSheet1.Name & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & sourceSheet1.Name & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & sourceSheet1.Name
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'Sum for Month of December
With outputSheet
OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("U12:U" & OutputLastRow).Formula = _
"=SUMPRODUCT(('" & sourceSheet1.Name & "'!$I$13:$I$" & SourceLastRow1 & ")*('" & sourceShe
et1.Name & "'!D$13:D$" & SourceLastRow1 & "=$U$10)*('" & sourceSheet1.Name & "'!A$13:A$" & SourceLastR
ow1 & "=$A12)*('" & sourceSheet1.Name & "'!C$13:C$" & SourceLastRow1 & "=$C12)*('" & sourceSheet1.Name
& "'!E$13:E$" & SourceLastRow1 & "=$F12))"
End With
'FromTo Brand ID
With outputSheet
OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("AC12:AC" & OutputLastRow).Formula = _
"=VLOOKUP(Z12,'" & sourceSheet2.Name & "'!$F$3:$I$" & SourceLastRow2 & ",3,FALSE)"
End With
'Proprietary Status
With outputSheet
OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("AE12:AE" & OutputLastRow).Formula = _
"=INDEX('" & sourceSheet3.Name & "'!$K$2:$K$" & SourceLastRow3 & ",MATCH($Z12,'" & sourceSheet
3.Name & "'!$C$2:$C$" & SourceLastRow3 & ",0),1)"
End With
'Sector
With outputSheet
OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("X12:X" & OutputLastRow).Formula = _
"=IF($D12="""","""",$D12)"
End With
'Order Guide
With outputSheet
OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("Y12:Y" & OutputLastRow).Formula = _
"=IF($E12="""","""",$E12)"
End With
'Stocking Status
With outputSheet
OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("AD12:AD" & OutputLastRow).Formula = _
"=INDEX('" & sourceSheet4.Name & "'!I$2:I$" & SourceLastRow4 & ",MATCH(1,INDEX((A12='" & sourc
eSheet4.Name & "'!A$2:A$" & SourceLastRow4 & ")*(Z12='" & sourceSheet4.Name & "'!B$2:B$" & SourceLastR
ow4 & "),0,1),0),1)"
End With
'Pack / Size
With outputSheet
OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("AB12:AB" & OutputLastRow).Formula = _
"=IFERROR(VLOOKUP(Z12,'" & sourceSheet1.Name & "'!$E$3:$G$" & SourceLastRow1 & ",3,FALSE),""""
)"
End With
'Calculation Formulas
'Calculate Number of Months for Average
'Jan
With outputSheet
OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("J9").Formula = _
"=IF(SUM($J12:$J" & OutputLastRow & ")<>0,1,0)"
.Range("J9").Font.Color = vbWhite
End With
'Feb
With outputSheet
OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("K9").Formula = _
Module1 - 6
.Range("U9").Font.Color = vbWhite
End With
'Total Number of Months
With outputSheet
.Range("V9").Formula = _
"=SUM($J9:$U9)"
.Range("V9").Font.Color = vbWhite
End With
'Paste Values
'With outputSheet
'OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
'.Range("Z12:Z" & OutputLastRow).Copy
'.Range("Z12:Z" & OutputLastRow).PasteSpecial Paste:=xlPasteValues
'Application.CutCopyMode = False
'End With
'Conditional Formatting
'Helper Column 1 - Does FROM Product Number exist in Sysco OG
With outputSheet
OutputLastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
.Range("BC12:BC" & OutputLastRow).Formula = _
"=IF(MATCH($F12,'" & sourceSheet3.Name & "'!$C$2:C$" & SourceLastRow3 & ",0),""Yes"",""No"
")"
End With
End Sub