Hi all!
I am trying to write VBA code to execute the following (visual screenshot attached)
If the value in column C of the pivot worksheet isn't found within column G (specific to the material in column B), I need to update the qty in the Overview tab for the missing size to 0.
For example, in the first screenshot below, size 16 (column C value) for material ABCDEF-111 (column B value) is not found in columns F:G. The material is found in column F, and the size is found in column G, but not the unique Material size (specific to B11 and C11).
After identifying ABCDEF-111 size 16 as a non match, I need to go into the worksheet "Overview" and find the size in column B. Once located (row 14 in the screenshot, size 16) I need to identify the column containing the material (cell C2 in this instance, so column C) and at that intersection (row 14 column C) I need to update the value to 0 and change it to red font.
My stab at the code below, before I came across the issue of, iserror finding size 16 from column C in column G, but not recognizing the material was different. I played around with it, but couldn't figure it out. The code might be scrap work at this point, but wanted to show my train of thought....
I appreciate any help, guidance or direction in advance!
I am trying to write VBA code to execute the following (visual screenshot attached)
If the value in column C of the pivot worksheet isn't found within column G (specific to the material in column B), I need to update the qty in the Overview tab for the missing size to 0.
For example, in the first screenshot below, size 16 (column C value) for material ABCDEF-111 (column B value) is not found in columns F:G. The material is found in column F, and the size is found in column G, but not the unique Material size (specific to B11 and C11).
After identifying ABCDEF-111 size 16 as a non match, I need to go into the worksheet "Overview" and find the size in column B. Once located (row 14 in the screenshot, size 16) I need to identify the column containing the material (cell C2 in this instance, so column C) and at that intersection (row 14 column C) I need to update the value to 0 and change it to red font.
My stab at the code below, before I came across the issue of, iserror finding size 16 from column C in column G, but not recognizing the material was different. I played around with it, but couldn't figure it out. The code might be scrap work at this point, but wanted to show my train of thought....
VBA Code:
Dim sizevalue As Range, overview_size_rng As Range, overview_mat_rng as range
Dim ranae As Integer, LR_col_B as integer, LCol as integer
ranae = 0
LR_col_B = Sh2.Cells(Rows.count, 2).End(xlUp).row 'Last row number in column B of overview worksheet (overview tab is Sh2)
LCol = Sh2.Cells(2, Columns.count).End(xlToLeft).Column 'Last column in row 2 of overview worksheet
LastRow2 = 6 'this needs to be 6 starting off
i_Pivot_row_number = Cells(Rows.count, 2).End(xlUp).row
i_PivotTable_G_row_number = Cells(Rows.count, 6).End(xlUp).row
Set overview_size_rng = Sh2.Range(Cells(1, 2), Cells(LR_col_B, 2)) 'Size range in column B
Set overview_mat_rng = Sh2.Range(Cells(2, 1), Cells(2, LCol)) 'Size range in column B
Sheets("Pivot").Activate
For Each sizevalue In Range(Cells(4, 3), Cells(i_Pivot_row_number, 3)) 'For each size value in column C of the PivotTab
If sizevalue.offset(0, -1).Value = sizevalue.offset(0, 3).Value Then 'If the Material from column B matches the Material in column F
If IsError(Application.Match(sizevalue, Range("G:G"), 0)) Then 'If the size in column C is not found in column G
aa= Application.WorksheetFunction.Match(Cells(4 + ranae, 3), overview_size_rng, 0)
bb= Application.WorksheetFunction.Match(Cells(CurrentRow + ranae, 6), overview_mat_rng, 0) 'The col # where the material in row 2 of the Main tab aligns to column F of Order Details tab
Sh2.Cells(aa, bb).Value = "0"
Sh2.Cells(aa, bb).Font.Color = vbRed 'Red font
Sh2.Cells(aa, bb).Font.Bold = True 'Bold
Sh2.Cells(aa, bb).Font.Underline = True 'Underline
End If
End If
ranae = ranae + 1
Next sizevalue
I appreciate any help, guidance or direction in advance!