Countif and sumif in case of 2 ranges with VBA

vergab

New Member
Joined
Jun 21, 2016
Messages
22
I can usethe countif and sumif functions in case of 1 range. But there are 2 ranges wherewithI have to work and I don’t have any idea. I would like to collect the uniqueconnect between elements of two ranges, count how many are them and how much isthe total of their values. See the example. Can anybody help me?

[TABLE="class: outer_border, ******* 142"]
<colgroup><col span="2"><col></colgroup><tbody>[TR]
[TD]A range[/TD]
[TD]B range[/TD]
[TD]Value[/TD]
[/TR]
[TR]
[TD]aa[/TD]
[TD]ee[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]bb[/TD]
[TD]ee[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]cc[/TD]
[TD]gg[/TD]
[TD="align: right"]12[/TD]
[/TR]
[TR]
[TD]aa[/TD]
[TD]ff[/TD]
[TD="align: right"]4[/TD]
[/TR]
[TR]
[TD]dd[/TD]
[TD]gg[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD]bb[/TD]
[TD]ff[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD]cc[/TD]
[TD]gg[/TD]
[TD="align: right"]7[/TD]
[/TR]
[TR]
[TD]aa[/TD]
[TD]ee[/TD]
[TD="align: right"]7[/TD]
[/TR]
[TR]
[TD]aa[/TD]
[TD]ff[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD]aa[/TD]
[TD]ff[/TD]
[TD="align: right"]4[/TD]
[/TR]
</tbody>[/TABLE]
<strike></strike>

[TABLE="class: outer_border, ******* 245"]
<colgroup><col><col><col><col></colgroup><tbody>[TR]
[TD="colspan: 2"]unique connection between the elements of the ranges[/TD]
[TD]Quantity[/TD]
[TD]sum of values[/TD]
[/TR]
[TR]
[TD]aa[/TD]
[TD]ee[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]9[/TD]
[/TR]
[TR]
[TD]aa[/TD]
[TD]ff[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]13[/TD]
[/TR]
[TR]
[TD]bb[/TD]
[TD]ee[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]bb[/TD]
[TD]ff[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD]cc[/TD]
[TD]gg[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]19[/TD]
[/TR]
[TR]
[TD]dd[/TD]
[TD]gg[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]5[/TD]
[/TR]
</tbody>[/TABLE]


<strike></strike>
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
[TABLE="class: grid"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="class: grid"]
<tbody>[TR]
[TD][/TD]
[TD]
A
[/TD]
[TD]
B
[/TD]
[TD]
C
[/TD]
[TD]
D
[/TD]
[/TR]
[TR]
[TD]
1
[/TD]
[TD]A range[/TD]
[TD]B range[/TD]
[TD]Value[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
2
[/TD]
[TD]aa[/TD]
[TD]ee[/TD]
[TD]
2​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
3
[/TD]
[TD]bb[/TD]
[TD]ee[/TD]
[TD]
3​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
4
[/TD]
[TD]cc[/TD]
[TD]gg[/TD]
[TD]
12​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
5
[/TD]
[TD]aa[/TD]
[TD]ff[/TD]
[TD]
4​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
6
[/TD]
[TD]dd[/TD]
[TD]gg[/TD]
[TD]
5​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
7
[/TD]
[TD]bb[/TD]
[TD]ff[/TD]
[TD]
6​
[/TD]
[TD][/TD]
[/TR]
[TR]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$C$2:$C$11) copy down
 
Upvote 0
It is only an example what I put here. The real data base contains about 12.000 rows, and I need a macro code for it not only an Excel function. I have to count with all of unique connection.
 
Upvote 0
The pivot table is your best choice:


Excel 2010
ABCDEFGHIJ
1A rangeB rangeValue
2aaee2
3bbee3A rangeB rangeCount of ValueSum of Value2
4ccgg12aaee29
5aaff4aaff313
6ddgg5bbee13
7bbff6bbff16
8ccgg7ccgg219
9aaee7ddgg15
10aaff5
11aaff4
Sheet3


it can be recorded in a macro also
 
Upvote 0
Pivot is no good, because it has another surface than a spreadsheet I need. I need only the data from the Pivot in a spreadsheet.
 
Upvote 0
You can set the destination to anywhere you like, and paste as a value if you want to format it differently. Or you can just apply the formulas to the unique pivot table A and B range elements.
 
Upvote 0
Under "Choose where you want the PivotTable report to be placed" in the pivot table dialog box, click either the New or Existing Worksheet radio button and click on a single cell. Then drag fields into the sections you want (try different configurations if you need practice). Putting just the A and B ranges into Row Labels, then choosing tabular view in report layout-design will get you unique items. Or you can do this with the advanced filter, but then everything has to be on the same worksheet.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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