PREFACE
A current forum member helped me put the following code together which successfully accomplishes the following:
Identifies missing values from one column as compared to another (Columns A:C; aka SKU to SKU)
If a value is missing in Column A (which is present in Column C), report the missing values in Column E:F
If a value is missing in Column C (which is present in Column A), report the missing values in Column G:H
OBJECTIVE
To build upon this solution, I would like to compare a secondary set of Columns (B:D) to see if they match each other.
REQUIREMENT
Only successful (unique) matches from Columns A:C in the previous check are to be evaluated. In other words, the results produced as missing values from Columns A:C (which are visually represented in Columns E:H) are not to be evaluated
GREATER DETAIL
DESIRED RESULT
Columns I:K represent the desired result of the macro which I wish to be integrated into the code provided above.
A current forum member helped me put the following code together which successfully accomplishes the following:
Identifies missing values from one column as compared to another (Columns A:C; aka SKU to SKU)
If a value is missing in Column A (which is present in Column C), report the missing values in Column E:F
If a value is missing in Column C (which is present in Column A), report the missing values in Column G:H
VBA Code:
Sub SKUChecker()
Application.ScreenUpdating = False
Worksheets("TRUE-UP").Activate
Dim lrA As Long
Dim lrC As Long
Dim rngA As Range
Dim rngC As Range
Dim cell As Range
' Find last row with data in column A
lrA = Cells(Rows.Count, "A").End(xlUp).Row
' Find last row with data in column C
lrC = Cells(Rows.Count, "C").End(xlUp).Row
' Set data ranges
Set rngA = Range("A2:A" & lrA)
Set rngC = Range("C2:C" & lrC)
' Loop through all rows in column C
For Each cell In rngC
' Search for value in column A
If Application.WorksheetFunction.CountIf(rngA, cell.Value) = 0 Then
' Copy value to column E
Cells(Rows.Count, "E").End(xlUp).Offset(1, 0) = cell.Value
End If
Next cell
' Loop through all rows in column A
For Each cell In rngA
' Search for value in column C
If Application.WorksheetFunction.CountIf(rngC, cell.Value) = 0 Then
' Copy value to column G
Cells(Rows.Count, "G").End(xlUp).Offset(1, 0) = cell.Value
End If
Next cell
'Corresponding Identifier for Column F
'=IF(E2<>"",VLOOKUP(E2,C:D,2,0),"")
With Range("F2:F" & Range("A" & Rows.Count).End(xlUp).Row)
.FormulaR1C1 = _
"=IF(RC[-1]<>"""",VLOOKUP(RC[-1],C[-3]:C[-2],2,0),"""")"
.Value = .Value
End With
'Corresponding Identifier for Column H
'=IF(G2<>"",VLOOKUP(G2,A:B,2,0),"")
With Range("H2:H" & Range("A" & Rows.Count).End(xlUp).Row)
.FormulaR1C1 = _
"=IF(RC[-1]<>"""",VLOOKUP(RC[-1],C[-7]:C[-6],2,0),"""")"
.Value = .Value
End With
Application.ScreenUpdating = True
End Sub
OBJECTIVE
To build upon this solution, I would like to compare a secondary set of Columns (B:D) to see if they match each other.
REQUIREMENT
Only successful (unique) matches from Columns A:C in the previous check are to be evaluated. In other words, the results produced as missing values from Columns A:C (which are visually represented in Columns E:H) are not to be evaluated
GREATER DETAIL
- Stated differently - Source Identifier (Column B) pairs with its respective Source SKU (Column A), so if the matching Remote SKU (Column C) has a different Remote Identifier, display the results as shown in Columns I:K
- The evaluation only occurs in one direction, meaning Columns A:B are the key fields to which Column D must match in order to be accurate.
- To make the anomaly easy to view, I've highlighted the non-matching values in Orange in the diagram below.
DESIRED RESULT
Columns I:K represent the desired result of the macro which I wish to be integrated into the code provided above.
MRE-FORMUM.SMPL.xlsx | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | |||
1 | SOURCE SKU | SOURCE IDENTIFIER | REMOTE SKU | REMOTE IDENTIFIER | MISSING FROM A | MISSING FROM B | MISSING FROM C | MISSING FROM D | SOURCE SKU | SOURCE IDENTIFIER MISMATCH | IDENTIFIER MISMATCH | ||
2 | ABC-123-001 | A11QEUX | ABC-123 | A11QESF | ABC-123 | A11QESF | ABC-123-003 | A11QESI | ABC-123-001 | A11QEUX | A11QESG | ||
3 | ABC-123-002 | A11QESH | ABC-123-001 | A11QESG | ABC-123-005 | A11QESK | ABC-123-004 | A11QETR | A11QESJ | ||||
4 | ABC-123-003 | A11QESI | ABC-123-002 | A11QESH | ABC-123-006 | A11QESL | |||||||
5 | ABC-123-004 | A11QETR | ABC-123-004 | A11QESJ | |||||||||
6 | ABC-123-005 | A11QESK | |||||||||||
7 | ABC-123-006 | A11QESL | |||||||||||
TRUE-UP |