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?

A rangeB rangeValue
aaee2
bbee3
ccgg12
aaff4
ddgg5
bbff6
ccgg7
aaee7
aaff5
aaff4

<colgroup><col span="2"><col></colgroup><tbody>
</tbody>
<strike></strike>

unique connection between the elements of the rangesQuantitysum of values
aaee29
aaff313
bbee13
bbff16
ccgg219
ddgg15

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>


<strike></strike>
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

<tbody>
</tbody>

A
B
C
D
1
A rangeB rangeValue
2
aaee
2​
3
bbee
3​
4
ccgg
12​
5
aaff
4​
6
ddgg
5​
7
bbff
6​
8
ccgg
7​
9
aaee
7​
10
aaff
5​
11
aaff
4​
12
13
14
Quantitysum of values
15
aaee
2​
9​
16
aaff
3​
13​
17
bbee
1​
3​
18
bbff
1​
6​
19
ccgg
2​
19​
20
ddgg
1​
5​

<tbody>
</tbody>

c15=SUMPRODUCT(--($A$2:$A$11&$B$2:$B$11=A15&B15)) copy down

d15=SUMPRODUCT(--($A$2:$A$11&$B$2:$B$11=A15&B15),$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,214,422
Messages
6,119,396
Members
448,891
Latest member
tpierce

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