Private Sub M1_Reset_Sheet()
Application.DisplayAlerts = False
'=================================================================================================================================
'Created By Halley Szeto, PI Analyst, Customer Excellence - 12 May 21
'Resets All Sheets
'=================================================================================================================================
'Confirmation
'User Input
iRConf = MsgBox("This will remove submitted SKUs" & vbCrLf & vbCrLf & _
"Proceed?", vbYesNo, "Reset Confirmation")
'If no
If iRConf = vbNo Then
Exit Sub
End If
'Reset Data SKUs
'Activate Sheet
iwsDT1.Activate
'Delete All
On Error Resume Next
Range("A1:A" & Range("B" & Rows.Count).End(xlUp).Row).EntireRow.Delete
'Reset Headers
Range("A1") = "SKU"
Range("B1") = "Status"
Range("C1") = "Plant"
'Set Dropdown for Status
'Block/Unblock
With iwsDT1.Range("B2:B1000").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="='" & iwsCS.Name & "'!T3:T4"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
'Reset Tracker Sheet
'Activate Sheet
iwsDISP1.Activate
'Set Font
With iwsDISP1.Range("E7:W" & Range("A" & Rows.Count).End(xlUp).Row).Font
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
End With
'Find Unblock from previous run and set to open
For Each iColCK In Range("E6:W6")
'Select and Get Column Unblock
iColCK.Select
iColFmt = Left(Right(Cells(1, iColCK.Column).Address, _
Len(Cells(1, iColCK.Column).Address) - 1), _
Application.Search("$", Right(Cells(1, iColCK.Column).Address, _
Len(Cells(1, iColCK.Column).Address) - 1)) - 1)
'Loop and Set Unblock to Open
'Set Unblock Row
iDelCt = Application.IfError(Application.Match("Unblock", iwsDISP1.Range(iColFmt & ":" & iColFmt), 0), 0)
'Do Until all reset
Do Until iDelCt = 0
'Set Text
Range(iColFmt & iDelCt).Select
Range(iColFmt & iDelCt) = "Open"
'Set Green Format
With Range(iColFmt & iDelCt).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
'Reset Unblock Row
iDelCt = Application.IfError(Application.Match("Unblock", iwsDISP1.Range(iColFmt & ":" & iColFmt), 0), 0)
Loop
'Loop and Set Block to Closed
'Set Unblock Row
iDelCt = Application.IfError(Application.Match("Block", iwsDISP1.Range(iColFmt & ":" & iColFmt), 0), 0)
'Do Until all reset
Do Until iDelCt = 0
'Set Text
Range(iColFmt & iDelCt).Select
Range(iColFmt & iDelCt) = "Closed"
'Reset Unblock Row
iDelCt = Application.IfError(Application.Match("Block", iwsDISP1.Range(iColFmt & ":" & iColFmt), 0), 0)
Loop
Next iColCK
Assistant
'Reset Error Report
'Activate Sheet
iwsDISP2.Activate
'Remove All Data
On Error Resume Next
Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).EntireRow.Delete
'Reset Headers
Range("A1") = "SKU"
Range("B1") = "Status"
Range("C1") = "Plant"
Range("D1") = "Error Reason"
End Sub
Private Sub M2_Load_Submission_Data()
Application.DisplayAlerts = False
'=================================================================================================================================
'Created By Halley Szeto, PI Analyst, Customer Excellence - 11 Jun 21
'Loads Data
'=================================================================================================================================
Dim iwbSub As Workbook
'Select File to Load
'Set Pathway to Open to
'ChDir ActiveWorkbook.Path,
'Run Dialog with Cancellation Error Handling
cancel = Application.GetOpenFilename _
(Title:="Select Central OU Submission Form to Load")
If cancel = False Then
MsgBox ("Import Session Ended")
Exit Sub
End If
With Workbooks.Open(cancel)
End With
'Set variable Name
Set iwbSub = ActiveWorkbook
Dim iwsImp As Worksheet
'Loop Through All Worksheets
'Activate Workbook
iwbSub.Activate
'Loop and Import Data
For Each iwsImp In Worksheets
'Activate Workbook
iwbSub.Activate
'Unhide workbook if necessary
On Error Resume Next
iwsImp.Visible = True
'Activate Sheet
iwsImp.Activate
'Check Sheet Name - Save if is registered site
'Get Initial Sheet Name
iLoc = Left(iwsImp.Name, 4)
'Skip if Sheet Name is List
If iLoc = "List" Then
GoTo iFunctSkip
End If
'Execute Test
'Activate Sheet
iwsImp.Activate
'Check Database
iLocTest = Application.IfError(Application.Match(iLoc, iwsCS.Range("O:O"), 0), 0) + _
Application.IfError(Application.Match(iLoc, iwsCS.Range("N:N"), 0), 0)
'Actions Test
'If Valid - Import Data
If iLocTest > 0 Then
'Test If Data Exists to Import
If Range("A" & Rows.Count).End(xlUp).Row > 1 Then
'Copy Data
iwsImp.Activate
Range("A2:B" & Range("A" & Rows.Count).End(xlUp).Row).Copy
'Paste Data
iwsDT1.Activate
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Fill Site Number
Range("C" & Range("C" & Rows.Count).End(xlUp).Row + 1 & _
":C" & Range("A" & Rows.Count).End(xlUp).Row) = iLoc
Else
GoTo iFunctSkip
End If
'If Not Valid Set Warning
Else
'Generate Error message
MsgBox ("WARNING! Invalid sheet name detected!" & vbCrLf & vbCrLf & _
"Please validate:" & vbCrLf & vbCrLf & _
iwsImp.Name)
'Error handle
GoTo iFunctSkip
End If
iFunctSkip:
Next iwsImp
'Close Workbook with no Saving
iwbSub.Close savechanges:=False
'Finalize Report
'Set Final View on Data
iwsDT1.Activate
Range("A1").Select
'Set Final View
iwsCS.Activate
Range("A1").Activate
'Completion message
MsgBox ("Submission Data Loaded!")
End Sub
Private Sub M3_Compile_Report()
Application.DisplayAlerts = False
'=================================================================================================================================
'Created By Halley Szeto, PI Analyst, Customer Excellence - 13 May 21
'Compiles Data
'=================================================================================================================================
End Sub
Private Sub M4_Generate_Submission_Form()
Application.DisplayAlerts = False
'=================================================================================================================================
'Created By Halley Szeto, PI Analyst, Customer Excellence - 11 Jun 21
'Generates Distro Form
'=================================================================================================================================
Dim iwbSub As Workbook
Dim iwsSub As Worksheet
'Generage New sheet
'Add New Workbook
Workbooks.Add
Set iwbSub = ActiveWorkbook
Set iwsSub = iwbSub.ActiveSheet
'Generate List Sheet
'Activate Workbook
iwsSub.Activate
'Change Sheet Name
iwsSub.Name = "List"
'Set List
Range("A1") = "Block"
Range("A2") = "Unblock"
'Generate New List
'Copy Data
iwsCFT1.Activate
Range("A1:B" & Range("A" & Rows.Count).End(xlUp).Row).Copy
'Paste Data
iwsSub.Activate
Range("C1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Convert To Numbers
iwsSub.Activate
Columns("C:C").TextToColumns Destination:=Range("C1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Dim iwsTSN As Worksheet
'Loop and Generate Sheets
'Activate Sheet
iwsCS.Activate
'Loop Through OU List and Grab all West
For Each iOU In Range("Q3:Q" & Range("Q" & Rows.Count).End(xlUp).Row)
'Activate Sheet
iwsCS.Activate
'Select and get row
iOU.Select
iOUR = iOU.Row
'Save Data
iNum = Range("O" & iOUR) 'MU
iOUT = Range("Q" & iOUR) 'OU
iLoc = Range("S" & iOUR) 'Location
iSSTr = iNum & "-" & iLoc 'Sheet String
'Check if OU is West
Select Case iOUT
Case "Central"
'Activate Workbook
iwbSub.Activate
'Add Sheet
On Error Resume Next
Sheets.Add(After:=iwbSub.Sheets(iwbSub.Sheets.Count)).Name = iSSTr
Set iwsTSN = iwbSub.Sheets(iSSTr)
'Activate Sheet
iwsTSN.Activate
'Generate Headers
Range("A1") = "SKU"
Range("B1") = "Status"
Range("C1") = "Description"
'Generate List
With Range("B2:B500").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="='" & iwsSub.Name & "'!A1:A2"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
'Generate Formula for Description
iwsTSN.Activate
Range("C2") = "=IF(ISBLANK(A2)=TRUE,"""",XLOOKUP(A2," & iwsSub.Name & "!C:C," & iwsSub.Name & "!D:D,"""",0))"
Range("C2").AutoFill Destination:=Range("C2:C500")
End Select
Next iOU
'Save Book
'Activate Workbook
iwbSub.Activate
'Hide List Sheet
On Error Resume Next
iwsSub.Visible = False
'Save Copy
iwbSub.SaveCopyAs iSPth & iwbNew
'Close Submission Book No Save
iwbSub.Close savechanges:=False
'Finalize Report
'Activate Sheet
iwsCS.Activate
'Set Final View
Range("A1").Select
'Completion Message
MsgBox ("Submission Form Generated!")
End Sub
Private Sub M5_Archive_SKUs()
Application.DisplayAlerts = False
'=================================================================================================================================
'Created By Halley Szeto, PI Analyst, Customer Excellence - 9 Jun 21
'Loop to Archive Items based on Rules
'Activate Sheet
iwsDISP1.Activate
'Loop Through SKUs
For Each IArc In Range("A7:A" & Range("A" & Rows.Count).End(xlUp).Row)
'Activate Sheet
iwsDISP1.Activate
'Select and Get Row
IArc.Select
iArcR = IArc.Row
'Save Variables
iODL = UCase(Range("C" & iArcR)) 'Delist Flag
iStat = Range("D" & iArcR) 'Status
iOCt = Application.CountIf(iwsDISP1.Range("E" & iArcR & ":K" & iArcR & ""), "Open") 'Open Count
'Initial Delist Check
Select Case iODL
Case "X" 'Item Delisted
'Check Open Count
Select Case iOCt
Case "0" 'Move
'Import
'Copy
iwsDISP1.Activate
Range("A" & iArcR & ":K" & iArcR).Copy
'Paste Data
iwsDT2.Activate
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Set Date Stamp
Range("L" & Range("A" & Rows.Count).End(xlUp).Row) = Date
'Set Archive Flag
iwsDISP1.Activate
Range("C" & iArcR) = "ARCHIVED"
Case Else 'Still Open in Locations
'No Action
End Select
Case Else 'Not On Delist
'Check Status
Select Case iStat
Case "LTO" 'LTO Status
'Check Open Count
Select Case iOCt
Case 0 'None Open
'Import
'Copy
iwsDISP1.Activate
Range("A" & iArcR & ":K" & iArcR).Copy
'Paste Data
iwsDT2.Activate
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Set Date Stamp
Range("L" & Range("A" & Rows.Count).End(xlUp).Row) = Date
'Set Archive Flag
iwsDISP1.Activate
Range("C" & iArcR) = "ARCHIVED"
Case Else 'Some Locations Open
'No Action
End Select
Case "Long Term OOS", "", " ", 0 'Long Term Out of Stock and Blanks
'Check Open Count
Select Case iOCt
Case 0 'All Closed
'No Action
Case 7 'All Open
'Import
'Copy
iwsDISP1.Activate
Range("A" & iArcR & ":K" & iArcR).Copy
'Paste Data
iwsDT2.Activate
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Set Date Stamp
Range("L" & Range("A" & Rows.Count).End(xlUp).Row) = Date
'Set Archive Flag
iwsDISP1.Activate
Range("C" & iArcR) = "ARCHIVED"
Case Else 'Some location Open
'No Action
End Select
End Select
End Sub
Private Sub S2_Compile_Data()
Application.DisplayAlerts = False
'=================================================================================================================================
'Created By Halley Szeto, PI Analyst, Customer Excellence - 13 May 21
'Compiles Data
'=================================================================================================================================
End Sub
Private Sub S3_Finalize_Report()
Application.DisplayAlerts = False
Dim iDtaRng As Range
'=================================================================================================================================
'Created By Halley Szeto, PI Analyst, Customer Excellence - 13 May 21
'Finalizes Report and Generates Distro Email
'=================================================================================================================================
'Generate Date on Tracker Sheet
'Activate Sheet
iwsDISP1.Activate
Range("C1") = "Current Week " & iFWk
Dim iwbFmt As Workbook
Dim iwsVis As Worksheet
'Generate Copies
'Tracker
'Save Copy As
iwb.SaveCopyAs iSPth & iwbNew1
'Open and Format
'Open Book
Workbooks.Open iSPth & iwbNew1
Set iwbFmt = ActiveWorkbook
'Set View
'Activate Workbook
iwbFmt.Sheets(iwsDISP1.Name).Activate
'Set View
Range("A1").Select
Range("E7").Select
Range("A1").Select
'Hide/Unhide Sheets
'Activate Workbook
iwbFmt.Activate
'Loop and Hide
For Each iwsVis In Worksheets
'Case select set hide/Unhide
Select Case iwsVis.Name
Case iwsDISP1.Name
On Error Resume Next
iwsVis.Visible = True
Case Else
On Error Resume Next
iwsVis.Visible = False
End Select
Next iwsVis
'Save and Close workbook
iwbFmt.Save
iwbFmt.Close savechanges:=True
'Submission Data
'Save Copy As
iwb.SaveCopyAs iSPth & iwbNew2
'Open and Format
'Open Book
Workbooks.Open iSPth & iwbNew2
Set iwbFmt = ActiveWorkbook
'Set View
'Activate Workbook
iwbFmt.Sheets(iwsDT1.Name).Activate
'Set View
Range("A1").Select
'Hide/Unhide Sheets
'Activate Workbook
iwbFmt.Activate
'Loop and Hide
For Each iwsVis In Worksheets
'Case select set hide/Unhide
Select Case iwsVis.Name
Case iwsDT1.Name
On Error Resume Next
iwsVis.Visible = True
Case Else
On Error Resume Next
iwsVis.Visible = False
End Select
Next iwsVis
'Save and Close workbook
iwbFmt.Save
iwbFmt.Close savechanges:=True
'Distribute to Processing if Option Selected
If iEMConf = "Yes" Then
'Activate Sheet
iwsCS.Activate
'Generate To Email
If Range("K" & Rows.Count).End(xlUp).Row > 2 Then
For Each iEM In Range("K3:K" & Range("K" & Rows.Count).End(xlUp).Row)
'Select and Get Row
iEM.Select
iEMRw = iEM.Row
'Generate String
iEMTo = iEMTo & Range("K" & iEMRw) & "; "
Next iEM
Else
iEMTo = ""
End If
'Generate CC Email
If Range("L" & Rows.Count).End(xlUp).Row > 2 Then
For Each iEM In Range("L3:L" & Range("L" & Rows.Count).End(xlUp).Row)
'Select and Get Row
iEM.Select
iEMRw = iEM.Row
'Generate String
iEMCC = iEMCC & Range("L" & iEMRw) & "; "
Next iEM
Else
iEMCC = ""
End If
'Generate Subject Line
iSubj = "Central - Master Data Delist Tracker - " & iDStr
'Generate Body
iMsg = "Hello Everyone," & vbCrLf & vbCrLf & _
"Attached is the delist tracker for " & iDStr & "." & vbCrLf & vbCrLf & _
"Thanks," & vbCrLf
'Generate Email
Dim olApp As Object
Dim olMail As Object
'Set Objects
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(olMailItem)
'Generate Email
With olMail
.To = iEMTo
.CC = iEMCC
.Subject = iSubj
.body = iMsg
.Attachments.Add iSPth & iwbNew2
.Display
End With
'Clear Objects
Set olMail = Nothing
Set olApp = Nothing
End If
'Distribute to General Option Selected
If iEMConf1 = "Yes" Then
'Activate Sheet
iwsCS.Activate
'Generate To Email
If Range("I" & Rows.Count).End(xlUp).Row > 2 Then
For Each iEMG In Range("I3:I" & Range("I" & Rows.Count).End(xlUp).Row)
'Select and Get Row
iEMG.Select
iEMRw = iEMG.Row
'Generate String
iEMGTo = iEMGTo & Range("I" & iEMRw) & "; "
Next iEMG
Else
iEMGTo = ""
End If
'Generate CC Email
If Range("J" & Rows.Count).End(xlUp).Row > 2 Then
For Each iEMG In Range("J3:J" & Range("J" & Rows.Count).End(xlUp).Row)
'Select and Get Row
iEMG.Select
iEMRw = iEMG.Row
'Generate String
iEMGCC = iEMGCC & Range("J" & iEMRw) & "; "
Next iEMG
Else
iEMGCC = ""
End If
'Generate Subject Line
iSubjG = "Central - Delist Tracker - " & iDStr
'Generate Body - Depends on If Error items Found
If iErrCt = 0 Then
iMsgG = "Hello Everyone," & "" & "" & _
"Attached is the delist tracker for " & iDStr & "." & "" & "" & _
"Thanks," & ""
Else
iMsgG = "Hello Everyone," & "" & "" & _
"Attached is the delist tracker for " & iDStr & "." & "" & "" & _
"Items were not loaded due to errors detected" & "" & _
"Please review and resubmit the following items:" & "" & "" & _
RangetoHTML(iDtaRng) & "" & "" & "Thanks," & ""
End If
'Generate Email
'Set Objects
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(olMailItem)
'Generate Email
With olMail
.To = iEMGTo
.CC = iEMGCC
.Subject = iSubjG
.HTMLbody = iMsgG
.Attachments.Add iSPth & iwbNew1
.Display
End With
'Clear Objects
Set olMail = Nothing
Set olApp = Nothing
End If
End Sub
Private Sub Reconcile()
Application.DisplayAlerts = False
Dim iDtaRng As Range
'=================================================================================================================================
'Created By Halley Szeto, PI Analyst, Customer Excellence - 13 May 21
'Finalizes Report and Generates Distro Email
'=================================================================================================================================
'Save Week
iFWk = iwsCS.Range("D2")
'Execute Reset Call
Call M1_Reset_Sheet
Dim iwbSAP As Workbook
Dim iwsSAP As Worksheet
'Select File to Load
'Set Pathway to Open to
'ChDir ActiveWorkbook.Path
'Run Dialog with Cancellation Error Handling
cancel = Application.GetOpenFilename _
(Title:="Select Central OU Reconcile File to Load")
If cancel = False Then
MsgBox ("Import Session Ended")
Exit Sub
End If
With Workbooks.Open(cancel)
End With
'Set variable Name
Set iwbSAP = ActiveWorkbook
Set iwsSAP = iwbSAP.ActiveSheet
Application.ScreenUpdating = False
Dim iwsTMP1 As Worksheet
'Generate Temp Sheet
'Activate Sheet
iwb.Activate
'Remove Temp Sheet if already exists
On Error Resume Next
iwb.Sheets("TEMP").Delete
'Generate New Sheet
Sheets.Add.Name = "TEMP"
Set iwsTMP1 = iwb.Sheets("TEMP")
'Import Data To Main Sheet
'Copy Data
iwsSAP.Activate
Range("A1:F" & Range("A" & Rows.Count).End(xlUp).Row).Copy
'Paste Data
iwsTMP1.Activate
Range("A1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Close SAP workbook no save
iwbSAP.Close savechanges:=False
'Execute format and clean
'Clean to just relevant Plants and SKUs
'Activate Sheet
iwsTMP1.Activate
'Text to columns material
Columns("D:D").TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
'Formula Insert and Fill
Range("G2") = "=IF(AND(" & _
"COUNTIFS('" & iwsDISP1.Name & "'!6:6,C2)>0," & _
"COUNTIFS('" & iwsDISP1.Name & "'!A:A,D2)>0)," & _
"""1-KEEP"",""2-DELETE"")"
Range("G2").AutoFill Destination:=Range("G2:G" & Range("A" & Rows.Count).End(xlUp).Row)
Range("G2:G" & Range("A" & Rows.Count).End(xlUp).Row).Copy
Range("G2:G" & Range("A" & Rows.Count).End(xlUp).Row).PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Sort To Group Items for deletion
iwsTMP1.Sort.SortFields.Clear
iwsTMP1.Sort.SortFields.Add2 _
Key:=Range("G2:G" & Range("A" & Rows.Count).End(xlUp).Row), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
With iwsTMP1.Sort
.SetRange Range("A1:G" & Range("A" & Rows.Count).End(xlUp).Row)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Loop and Delete Items
'Set initial Deletion Count
iDelCt = Application.CountIfs(iwsTMP1.Range("G:G"), "2-DELETE")
'Loop Until Deleted
Do Until iDelCt = 0
'Get Start and End Rows
iSRw = Application.Match("2-DELETE", iwsTMP1.Range("G:G"), 0)
iERw = iSRw + (iDelCt - 1)
'Select and Delete Items
Range("G" & iSRw & ":G" & iERw).Select
Range("G" & iSRw & ":G" & iERw).EntireRow.Delete
'ReSet initial Deletion Count
iDelCt = Application.IfError(Application.Match("2-DELETE", iwsTMP1.Range("G:G"), 0), 0)
Loop
'Remove Identifier
Columns("G:G").Delete
'Duplicates Scrub
'Activate sheet
iwsTMP1.Activate
'Generate Duplicates Identifier
Range("G1") = "Unique ID"
Range("H1") = "Duplicates Count"
'Insert Formulas
Range("G2") = "=C2&D2"
Range("H2") = "=IF(COUNTIFS(G:G,G2)>1,""2-DUP"","""")"
Range("G2:H2").AutoFill Destination:=Range("G2:H" & Range("A" & Rows.Count).End(xlUp).Row)
Range("G2:H" & Range("A" & Rows.Count).End(xlUp).Row).Copy
Range("G2:H" & Range("A" & Rows.Count).End(xlUp).Row).PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Duplicates Correction if detected
If Application.CountIfs(iwsTMP1.Range("H:H"), "2-DUP") > 1 Then
'Execute Scrub
'Sort data for Scrub
iwsTMP1.Sort.SortFields.Clear
iwsTMP1.Sort.SortFields.Add2 _
Key:=Range("G2:G" & Range("A" & Rows.Count).End(xlUp).Row), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
With iwsTMP1.Sort
.SetRange Range("A1:H" & Range("A" & Rows.Count).End(xlUp).Row)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Loop and Flag Items for Deletion
'Activate Sheet
iwsTMP1.Activate
'Loop and Execute Ident
For Each iDupCt In Range("H2:H" & Range("A" & Rows.Count).End(xlUp).Row)
'Select and Get row
iDupCt.Select
iDCRw = iDupCt.Row
'Save Start and End Rows
iUIDS = Range("G" & iDCRw)
iDRS = Application.Match(iUIDS, iwsTMP1.Range("G:G"), 0)
iDRE = iDRS + (Application.CountIfs(iwsTMP1.Range("G:G"),iUIDS)−1)E" & iDCRw), iwsTMP1.Range("E" & iDRS & ":E" & iDRE), 0) > 1 Then
Range("H" & iDCRw) = "2-DELETE"
Else
Range("H" & iDCRw) = "1-KEEP"
End If
Next iDupCt
'Sort and Delete all Items flagged for deletion
'Activate Sheet
iwsTMP1.Activate
'Sort Items for Deletion Groups
iwsTMP1.Sort.SortFields.Clear
iwsTMP1.Sort.SortFields.Add2 _
Key:=Range("H2:H" & Range("A" & Rows.Count).End(xlUp).Row), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
With iwsTMP1.Sort
.SetRange Range("A1:H" & Range("A" & Rows.Count).End(xlUp).Row)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Loop and Delete Items
'Set initial Deletion Count
iDelCt = Application.CountIfs(iwsTMP1.Range("H:H"), "2-DELETE")
'Loop Until Deleted
Do Until iDelCt = 0
'Get Start and End Rows
iSRw = Application.Match("2-DELETE", iwsTMP1.Range("H:H"), 0)
iERw = iSRw + (iDelCt - 1)
'Select and Delete Items
Range("H" & iSRw & ":H" & iERw).Select
Range("H" & iSRw & ":H" & iERw).EntireRow.Delete
'ReSet initial Deletion Count
iDelCt = Application.IfError(Application.Match("2-DELETE", iwsTMP1.Range("H:H"), 0), 0)
Loop
End If
'Identify Status
'Reset Columns
Columns("G:H").Delete
Range("G1") = "Status"
'Generate Formula
Range("G2") = "=IF(YEAR($F2)=9999,""Unblock"",""Block"")"
Range("G2").AutoFill Destination:=Range("G2:G" & Range("A" & Rows.Count).End(xlUp).Row)
Range("G2:G" & Range("A" & Rows.Count).End(xlUp).Row).Copy
Range("G2:G" & Range("A" & Rows.Count).End(xlUp).Row).PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Resort Data
Columns("C:C").Cut
Columns("A:A").Insert
Columns("G:G").Cut
Columns("A:A").Insert
Columns("E:E").Cut
Columns("A:A").Insert
'Import data to Submitted SKUs Sheet
iwsTMP1.Activate
Range("A2:C" & Range("A" & Rows.Count).End(xlUp).Row).Copy
iwsDT1.Activate
Range("A2").PasteSpecial xlPasteValues
Application.CutCopyMode = False
'Delete Temp Sheet
iwsTMP1.Delete
'Loop Through Each SKU and set tracker
'Replicate Actions
'Loop Through Replicate Actions Database
'Activate Sheet
iwsCS.Activate
'Generate Temp Sheet
'Remove Temp Sheet if Pre Existing
On Error Resume Next
iwb.Sheets("TEMP").Delete
'Generate New Temp Sheet
Dim iwsTMP As Worksheet
Sheets.Add.Name = "TEMP"
Set iwsTMP = iwb.Sheets("TEMP")
'Generate Headers
iwsTMP.Activate
Range("A1") = "SKU"
Range("B1") = "Status"
Range("C1") = "Plant"
'Activate Sheet
iwsCS.Activate
'Execute Loop and Search
For Each iRA In Range("AB3:AB" & Range("AB" & Rows.Count).End(xlUp).Row)
'Activate Sheet
iwsCS.Activate
'Select and Save Data
iRA.Select
iRAR = iRA.Row
iFP = Range("AB" & iRAR)
iTP = Range("AC" & iRAR)
'Execute Loop in Submitted SKUs
'Activate Sheet
iwsDT1.Activate
'Loop
For Each iCK In Range("C2:C" & Range("A" & Rows.Count).End(xlUp).Row)
'Activate Sheet
iwsDT1.Activate
'Save Variables
iCK.Select
iCKR = iCK.Row
iPlt = Range("C" & iCKR)
'Check if Replication Required
If iPlt = iFP Then
'Save Data
iSKU = Range("A" & iCKR)
iStat = Range("B" & iCKR)
'Set Temp Row
iwsTMP.Activate
iTMPR = Application.Range("A" & Rows.Count).End(xlUp).Row + 1
'Insert Data
Range("A" & iTMPR) = iSKU
Range("B" & iTMPR) = iStat
Range("C" & iTMPR) = iTP
End If
Next iCK
Next iRA
'Move Data Back to Data Sheet
'Activate Sheet
iwsTMP.Activate
'Check if Import Required
If Range("A" & Rows.Count).End(xlUp).Row > 1 Then
'Copy Data
iwsTMP.Activate
Range("A2:C" & Range("A" & Rows.Count).End(xlUp).Row).Copy
'Paste Data
iwsDT1.Activate
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End If
'Delete Temp Sheet
On Error Resume Next
iwsTMP.Delete
'Update Tracker
'Activate Sheet
iwsDT1.Activate
'Loop
For Each iSKU In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
'Activate Sheet
iwsDT1.Activate
'Select and get Data
iSKU.Select
iSRw = iSKU.Row
'Save data Sheet Variables
'Activate Sheet
iwsDT1.Activate
'Set Variables
iSKUN = Range("A" & iSRw) 'SKU
iStat = Range("B" & iSRw) 'Status
iPlnt = Range("C" & iSRw) 'Plant
'Set Tracker
'Activate Sheet
iwsDISP1.Activate
'Check if New Item - Skip
If Application.IfError(Application.Match(iSKUN, iwsDISP1.Range("A:A"), 0), 0) = 0 Then
GoTo iSkipProcess
Else
'Set Working Row
iWRw = Application.Match(iSKUN, iwsDISP1.Range("A:A"), 0)
End If
'Set Column/Range Variable
'Working Column
'Get Working Column
iWCol = Application.IfError(Application.Match(iPlnt, iwsDISP1.Rows("6:6"), 0), 0)
'Error Handler
If iWCol = 0 Then
GoTo iSkipProcess
Else
'Convert Column Number to Letter
iWCol = Left(Right(Cells(1, iWCol).Address, _
Len(Cells(1, iWCol).Address) - 1), _
Application.Search("$", Right(Cells(1, iWCol).Address, _
Len(Cells(1, iWCol).Address) - 1)) - 1)
End If
'Working Range
Dim iWRng As Range
Set iWRng = Range(iWCol & iWRw)
iWRng.Select
'Set Block/Unblock
Select Case iStat
Case "Block"
'Activate Sheet
iwsDISP1.Activate
'Set Week
iWRng = "Block"
'Set Formatting
'Highlight
With iWRng.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
'Font
With iWRng.Font
.Color = -16776961
.TintAndShade = 0
End With
Case "Unblock"
'Activate Sheet
iwsDISP1.Activate
'Set Open
iWRng = "Unblock"
'Set Formatting
'Highlight
With iWRng.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
'Font
With iWRng.Font
.Color = -16776961
.TintAndShade = 0
End With
End Select
iSkipProcess:
Next iSKU
'Completion Message
Application.ScreenUpdating = False
MsgBox ("Mass System Reconciliation Complete!")
End Sub
Function RangetoHTML(rng As Range)
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
'Create Temp File
TempFile = Environ$("temp") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
'Copy the range and create a new workbook to past the data in
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
'Publish the sheet to a htm file
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
'Read all data from the htm file into RangetoHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.readall
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
'Close TempWB
TempWB.Close savechanges:=False
'Delete the htm file we used in this function
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function >>include a condition that during reconciliation when the Material in the received reconciliation file is not available for any Plant Number in the tracker, then assign the SKU as "" for its respective plant number
To include the requested condition during reconciliation—when a Material (SKU) from the reconciliation file is not available in any Plant Number in the tracker, then assign the SKU as an empty string ("") for its respective plant numbers—you can modify the Reconcile subroutine in your VBA code.
Here's how you can implement this:
When a SKU is not found in the tracker: Add the SKU to the tracker and assign an empty string ("") to all existing plant columns for that SKU. This ensures that the SKU is present in the tracker, and it has empty values for all plants.
When a Plant Number is not found in the tracker: Do not add new plant columns. Instead, skip updating the value for that plant, effectively leaving it as an empty string ("") for that SKU and plant combination.
Here's the modified code for the relevant section in the Reconcile subroutine:
' Loop Through Each SKU and set tracker
' Activate Sheet
iwsDT1.Activate
' Loop through each SKU in the data sheet
For Each iSKU In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
' Activate Data Sheet and get data
iwsDT1.Activate
iSKU.Select
iSRw = iSKU.Row
iSKUN = Range("A" & iSRw) ' SKU
iStat = Range("B" & iSRw) ' Status
iPlnt = Range("C" & iSRw) ' Plant
' Activate Tracker Sheet
iwsDISP1.Activate
' Check if SKU exists in tracker
If Application.IfError(Application.Match(iSKUN, iwsDISP1.Range("A:A"), 0), 0) = 0 Then
' SKU not found in tracker - add SKU and assign "" to all existing plant columns
iWRw = Range("A" & Rows.Count).End(xlUp).Row + 1
Range("A" & iWRw) = iSKUN
Range("B" & iWRw) = Application.XLookup(Application.Text(iSKUN, 0), iwsCFT1.Range("A:A"), iwsCFT1.Range("B:B"), "N/A", 0)
' Generate Status List
With Range("D" & iWRw).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="='" & iwsCS.Name & "'!$AA$3:$AA$5"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
' Assign "" to all existing plant columns
iLastCol = iwsDISP1.Cells(6, Columns.Count).End(xlToLeft).Column
For iCol = 5 To iLastCol
iwsDISP1.Cells(iWRw, iCol).Value = ""
Next iCol
Else
' SKU exists in tracker
iWRw = Application.Match(iSKUN, iwsDISP1.Range("A:A"), 0)
End If
' Get the column for the plant
iWCol = Application.IfError(Application.Match(iPlnt, iwsDISP1.Rows("6:6"), 0), 0)
' Check if plant exists in tracker
If iWCol = 0 Then
' Plant not found in tracker - skip processing
GoTo iSkipProcess
Else
' Set the cell in tracker for SKU and plant
Set iWRng = iwsDISP1.Cells(iWRw, iWCol)
End If
' Update Tracker based on Status
Select Case iStat
Case "Block"
iWRng = "Block"
' Optional: Add formatting if needed
Case "Unblock"
iWRng = "Unblock"
' Optional: Add formatting if needed
End Select
iSkipProcess:
Next iSKU
Explanation:
Adding SKU to Tracker: If the SKU from the reconciliation file is not found in the tracker (iwsDISP1 sheet), the code adds the SKU to the tracker. It then assigns an empty string ("") to all existing plant columns for that SKU. This is done by looping through all plant columns starting from column 5 (assuming plant data starts from column 5) and setting the cell value to "".
Checking Plant in Tracker: If the plant number from the reconciliation file is not found in the tracker (i.e., there's no matching column in the tracker for that plant), the code skips updating the cell for that plant. This is because there's no column to assign a value to, and we're avoiding adding new plant columns during reconciliation.
By making these changes, the tracker will reflect that the SKU is not available for any plant (since all plant cells are set to ""), and it will not attempt to add new plant columns for plants that are not already in the tracker.
Note: Make sure to adjust the starting column index (iCol = 5) in the loop assigning "" to plant columns, based on the actual structure of your tracker sheet (iwsDISP1).
By implementing this modification, your reconciliation process will now handle SKUs not available in the tracker by assigning an empty string for its respective plant numbers, as per your requirement.