Counting Multi Criteria Occurrences in a Group of Records - vba

Nicha

New Member
Joined
Feb 10, 2023
Messages
40
Office Version
  1. 2016
Platform
  1. Windows
GroupBCResult
A1A123
A1#0
A1A546
A1#9
A2A678678
A2A678678
A2#5678
A3A532532
A3#0532
A3#0532



Regarding the data presented above, I need to Count occurrences on columns B and C, inside each Group, in order to get the value in [C] to fill the column [D] with it.
the idea is to count the combinations of the 'A' values in column B, with the numerical values in column C - in 'A' + Value combinations - using the below criteria's:
  • If there's only one 'A' in column B, the value to fill in column D is the correspondent value in the column C. This is the case of the Group (A3) with the value (532). Obviously, If this 'A' has no value on C, theres nothing to fill in column D.
  • If there's 2 or more 'A' in Column B with the same values in column C, the value for filling in column D is the one that result from that combination. This is the case of Group (A2) with value (678).

Note : The Group (A1) will not be filled because, although it has 2 'A's, they have different combinations since they have divergent values in column C.

This process could be a vba Function that I'll include inside the main(), that will check those 2 combinations, and if the function returns no value - case of Group (A1) - the Main() process will perform analisys on those groups, reading them line by line.

Can anyone help please?
 
Hi Kevin9999. Sorry for the inconvenience.
The code is working right, but I'm having trouble with the instruction that count's if the values in Column [C] are ">0". Thats because in real table the column [C] is Text.

VBA Code:
    '3. If more than one "A" in group
    If WorksheetFunction.CountIfs(r.Offset(, -1), "A", r, ">0") > 1 Then

So, theres a solution To Count if ">0" in a column with numbers formated as text; or count if those text values are numeric?

VBA Code:
Pseudo code:

    '3. If more than one "A" in group
    If WorksheetFunction.CountIfs(r.Offset(, -1), "A", r, "isNumeric") > 1 Then
Or
    '3. If more than one "A" in group
    If WorksheetFunction.CountIfs(r.Offset(, -1), "A", clng(r), ">0") > 1 Then


Thank's very, very mutch. The rest it's perfectly ok.

p.s. I can't change the format of column [C].
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Thats because in real table the column [C] is Text.
This is the first time you've mentioned this, and it does make a significant difference. I don't think the UDF approach will work now. You may have to go back to some kind of sub routine to (perhaps) convert column C to numeric - and then back again to text at the conclusion of the code? Just a suggestion - post a new thread with your existing UDF & ask if anyone can resolve the issue of column C being text not numeric. There's better brains than me on here that might have an elegant solution.
 
Upvote 0

Forum statistics

Threads
1,214,613
Messages
6,120,515
Members
448,968
Latest member
Ajax40

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