VBA To identify the non-match between a pivot table and a column of data

Oregon92

New Member
Joined
Jun 25, 2021
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
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....

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!
 

Attachments

  • pic 1.png
    pic 1.png
    24.5 KB · Views: 10
  • pic 2.png
    pic 2.png
    13.4 KB · Views: 10

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top