Summing values in one column if criteria met in another, quickly.

geoffreygroh

New Member
Joined
Dec 8, 2011
Messages
2
I'm trying to sum cells in column B, if their value in column A is the same. Unfortunately the values in column A will be different everyday. The way I do it currently is to use the advance filter to copy unique values of column A to column C. After I know the unique values in Column C I run an Array function =IF(ISBLANK($C2),"",SUM(IF(($A:$A=$C2),B:B,0)))
and I fill the column of cells with the formula.

The macro I use is basically just an edited "record macro" code. and it take quite a long time to calculate all the array formulas.

I was hoping someone knows a better/faster way to write this in order to decrease calculation time….
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Welcome to the forum,

With the macro you have recorded you can switch the screen updating, warnings and autocalculate off until it finishes running this would speed things up.

Maybe showing your code in your thread would help as well.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> cl()<br>Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>Application.DisplayAlerts = <SPAN style="color:#00007F">False</SPAN><br>Application.Calculation = xlCalculationManual<br><SPAN style="color:#007F00">'Your code goes here</SPAN><br><br>Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br>Application.DisplayAlerts = <SPAN style="color:#00007F">True</SPAN><br>Application.Calculation = xlCalculationAutomatic<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
I have an idea that may or may not be what you're looking for. You could use a simple if statement to determine if the value in column A is equal to the value in column B and return that value in column C.

In C2, type if(A2=B2,B2). It will only return a 0 if false, so it won't affect your sum. Then in column D, just do a SUM(C:C) and it will return the total value.

Hopefully something that might work for you.
 
Upvote 0
Do you need to sum all of column A and B if you can reduce that to say 500 you will save time
 
Upvote 0
The example I used is kind of the bare bones of what I'm doing. In actuality I need to do this procedure across tens of thousands of rows, and return the sums of multiple columns instead of just one. So I'm basically just repeating the bare bones procedure a lot.... So significant speed up is very import.

Trevor,
Thanks for the idea but it doesn't quicken it up as much as I hope.

Steve,
I've never used one, but I'll do some research.

Nicolia,
I think understand what you're getting at, but I don't think it will be practical, I want to sum the values in Column B if their value in A is the same, returning a list that will be much shorter.

Dryver,
I need to check a lot of cells, do you think That A2:A100000 would be a lot quicker than A:A?

I was hoping there was a way to store values in a VBA or something so that the calculation would speed...

Thanks for everyone ideas.


 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,593
Members
452,654
Latest member
mememe101

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