How to add values of a column only if certain condition is satisfied

niksnay

New Member
Joined
May 15, 2014
Messages
5
I'm learning Excel VBA programming, and I'm currently trying to get over an issue with how to sum up the values of a column if certain condition is satisfied.
I have one sheet which contains 10 columns in total i.e. from A to J. The Column "G" contain value of "9" but occurrence of this value is not fixed; it spreads randomly i.e. some cells contain null value (0) and some contains value 9 etc.

Column J contain a value at places only where there is a "9" present in Column "G", otherwise there is no value present in column J. Thus, Column J can contain a specific value only if there is a 9 present in a column G.

Now my question is , I want to add the values of the column "J" but I want to add only those block where there is a 9 present in Column G and the process continues till there is no empty cell encountered. Once , the macro found empty cell, it should again look for the value "9" in the column G and repeats the whole process until there is no more 9 present.

ABCDEFGHIJ
91.2
90
91.563
90

<tbody>
</tbody>


This is an example how my worksheet looks like, so there are cells in Column J which contains any value that can be any integer or decimal value or may be even 0 and there may be cells in column G and J which may contain no data.



ABCDEFGHIJ
91.2
90
91.563
Sum = 2.763
90
Sum = 0
95.4
90
90
98.5
Sum = 13.9

<tbody>
</tbody>

As, there is no more 9 present in the column G, the macro should get stopped.

Please give your suggestion and advice how should I do this task.

Thanks for your help in advance.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Except you absolutely have to use a macro or VBA

1. 'You can highlight all the cells in column J
2. Press F5 ("Go To" Dialog box), select Special
3. Select "Blank Cells" (Only the blank cells within the range get selected")
4. In the home tab, under the editing Group, click AUTOSUM

This sums up all values from the first non-blank value above it to the value just a cell above it.

You could try it out and see
 
Upvote 0

Forum statistics

Threads
1,215,474
Messages
6,125,024
Members
449,204
Latest member
LKN2GO

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