Formula to look at Column G&H in groups of data & returns the number repeated the most in each group.

Event2020

Board Regular
Joined
Jan 6, 2011
Messages
122
Office Version
  1. 2019
Platform
  1. Windows
I need a formula that 1st. Identifies each set of matching data working down the sheet (dynamically) and then looks at G2 down and in each set of date returns the duplicate number that appears the most and then does the same for Column H, all the way down the whole sheet until there is no more data.

The formula should be VBA if possible.

Columns G & H are not included in the set matching criteria as they do not have matching numbers and could be any combination of numbers.

In the xl2bb examples. the first one is sheet 1 (product List) of the work book and
the second is Sheet 2 (Product Data).

I also include a link to the workbook here
Example Workbook

Looking at my example, for
Red Paint that number would be Column G = 12 and Column H = 1058
Yellow Paint that would be Column G = 300 and Column H = 442
Black Paint that would be Colum G = 1 and Column H = 3

I have the VBA code below that looks at Track Sheet, Column A and if it is not null it then pulls the value from the same position on the Track Data sheet.

VBA Code:
Range("G2").Select                                        
ActiveCell.FormulaR1C1 = "=IF(RC[-6]="""","""",'Product Data'!RC)"                                        
                                        
Range("H2").Select                                        
ActiveCell.FormulaR1C1 = "=IF(RC[-7]="""","""",'Product Data'!RC)"


However, I am unable to workout how to have the formula identify and return the duplicates that appear the most in each set of data as I have already described.

Thank you in advance everyone.


Product List work sheet
Example.xlsx
ABCDEFGHIJK
1ProductProduct TypeData 1Data 2Data 3Data 4Number 1Number 2Data 5PricePACK TYPE
2Red PaintPowderData 1Data 2Data 3Data 4121058Data 522.99Tin
3Yellow PaintOilData 1Data 2Data 3Data 4300442Data 59.89Tube
4Black PaintPowderData 1Data 2Data 3Data 413Data 56.28Tin
5
6I need a formula that 1st. Identifies each set of matching data working down the sheet (dynamically) and then looks at G2 down and in each set of date returns the duplicate number that appears the most
7and then does the same for Column H, all the way down the whole sheet until there is no more data.
8
9The formula could be entered into each Cell in Columns G & H or it could be VBA
10Columns G & H are not included in the set matching criteria as they do not have matching numbers and could be any combination of numbers.
11
12Looking at my example, for
13Red Paint that number would be Column G = 12 and Column H = 1058
14Yellow Paint that would be Column G = 300 and Column H = 442
15Black Paint that would be Colum G = 1 and Column H = 3
16
17I have the VBA code below that looks at Track Sheet, Column A and if it is not null it then pulls the value from the same position on the Track Data sheet.
18
19Range("G2").Select
20ActiveCell.FormulaR1C1 = "=IF(RC[-6]="""","""",'Product Data'!RC)"
21
22Range("H2").Select
23ActiveCell.FormulaR1C1 = "=IF(RC[-7]="""","""",'Product Data'!RC)"
24
25However, I am unable to workout how to have the formula identify and return the duplicates that appear the most in each set of data as I have
26already described.
Product List


Product Data work sheet
Example.xlsx
ABCDEFGHIJK
1ProductProduct TypeData 1Data 2Data 3Data 4Number 1Number 2Data 5PricePACK TYPE
2Red PaintPowderData 1Data 2Data 3Data 4121058Data 522.99Tin
3Red PaintPowderData 1Data 2Data 3Data 4121058Data 522.99Tin
4Red PaintPowderData 1Data 2Data 3Data 4121058Data 522.99Tin
5Red PaintPowderData 1Data 2Data 3Data 441058Data 522.99Tin
6Red PaintPowderData 1Data 2Data 3Data 44652Data 522.99Tin
7Red PaintPowderData 1Data 2Data 3Data 42331Data 522.99Tin
8Red PaintPowderData 1Data 2Data 3Data 4122012Data 522.99Tin
9Red PaintPowderData 1Data 2Data 3Data 4121058Data 522.99Tin
10Red PaintPowderData 1Data 2Data 3Data 4121058Data 522.99Tin
11Yellow PaintOilData 1Data 2Data 3Data 4300442Data 59.89Tube
12Yellow PaintOilData 1Data 2Data 3Data 443442Data 59.89Tube
13Yellow PaintOilData 1Data 2Data 3Data 4300442Data 59.89Tube
14Yellow PaintOilData 1Data 2Data 3Data 4215678Data 59.89Tube
15Yellow PaintOilData 1Data 2Data 3Data 414442Data 59.89Tube
16Yellow PaintOilData 1Data 2Data 3Data 462789Data 59.89Tube
17Yellow PaintOilData 1Data 2Data 3Data 4300442Data 59.89Tube
18Yellow PaintOilData 1Data 2Data 3Data 43001233Data 59.89Tube
19Yellow PaintOilData 1Data 2Data 3Data 4300442Data 59.89Tube
20Black PaintPowderData 1Data 2Data 3Data 413Data 56.28Tin
21Black PaintPowderData 1Data 2Data 3Data 4145Data 56.28Tin
22Black PaintPowderData 1Data 2Data 3Data 4220Data 56.28Tin
23Black PaintPowderData 1Data 2Data 3Data 433Data 56.28Tin
24Black PaintPowderData 1Data 2Data 3Data 438Data 56.28Tin
25Black PaintPowderData 1Data 2Data 3Data 463Data 56.28Tin
26Black PaintPowderData 1Data 2Data 3Data 413Data 56.28Tin
27
28The data is entered on this page.
Product Data
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
A PQ solution.

Query "ProductData"
SQL:
let
    Source = Excel.CurrentWorkbook(){[Name="ProductData"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"Product Type", type text}, {"Data 1", type text}, {"Data 2", type text}, {"Data 3", type text}, {"Data 4", type text}, {"Number 1", Int64.Type}, {"Number 2", Int64.Type}, {"Data 5", type text}, {"Price", type number}, {"PACK TYPE", type text}})
in
    #"Changed Type"

Query "Result"
SQL:
let
    Source = ProductData,
    #"Grouped Rows" = Table.Group(Source, {"Product", "Product Type", "Data 1", "Data 2", "Data 3", "Data 4", "Data 5", "Price", "PACK TYPE"}, {{"Number 1", each List.Mode([Number 1]), type nullable number}, {"Number 2", each List.Mode([Number 2]), type nullable number}})
in
    #"Grouped Rows"
 
Upvote 0
A PQ solution.

Query "ProductData"
SQL:
let
    Source = Excel.CurrentWorkbook(){[Name="ProductData"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"Product Type", type text}, {"Data 1", type text}, {"Data 2", type text}, {"Data 3", type text}, {"Data 4", type text}, {"Number 1", Int64.Type}, {"Number 2", Int64.Type}, {"Data 5", type text}, {"Price", type number}, {"PACK TYPE", type text}})
in
    #"Changed Type"

Query "Result"
SQL:
let
    Source = ProductData,
    #"Grouped Rows" = Table.Group(Source, {"Product", "Product Type", "Data 1", "Data 2", "Data 3", "Data 4", "Data 5", "Price", "PACK TYPE"}, {{"Number 1", each List.Mode([Number 1]), type nullable number}, {"Number 2", each List.Mode([Number 2]), type nullable number}})
in
    #"Grouped Rows"
Hi

Thank you for your reply and suggestion which I appreciate.

How do I incorporate your PQ solution into the VBA code formulas that I provided?

The VBA is very important as the whole work book is functioning by using VBA.

Many thanks
 
Upvote 0
PQ code is totally different code then VBA code.

You may have to wait for a helper with VBA expertise.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

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