# VBA to take averages of a group of cells in a column based on true/false criteria

#### Pcool

##### Board Regular
I want to be able to take the average of grouped(based on the "true" in the B column) values(taken from the numbers in the A column) that will be displayed in the C column.
Does anyone know how to automate this using VBA or a formula?

 A1 Amount B1 True/False C1 Average 5 False 0 3 False 0 8 True =AVERAGE(A4:A10) 3 True 2 True 8 True 6 True 7 True 4 True 5 False 0 1 False 0 2 False 0 3 True 4 True 8 False 9 True 6 False 3 True 2 True

<tbody>
</tbody>

Last edited:

### Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use \$ signs: \$V\$2:\$Z\$99 will always point to V2:Z99, even after copying
what's the criteria for average? How do you know which values do you have put in the average formula?

what's the criteria for average? How do you know which values do you have put in the average formula?

Sorry about that, If it is "True" in Column B, then take the value from column A. I guess the real challenge is dynamically collecting groups in column A.

So in my above example A4:A10, A14:A15, A17, A18:A19 would be different groups resulting in 5.42, 3.5, 9, and 2.5 in column C

Any ideas on this one?

Can I bump this?
I want the end result to be like this
 1 A1 Amount B1 True/False C1 Average 2 5 False 0 3 3 False 0 4 8 True =AVERAGE(A4:A10) 5 3 True =AVERAGE(A4:A10) 6 2 True =AVERAGE(A4:A10) 7 8 True =AVERAGE(A4:A10) 8 6 True =AVERAGE(A4:A10) 9 7 True =AVERAGE(A4:A10) 10 4 True =AVERAGE(A4:A10) 11 5 False 0 12 1 False 0 13 2 False 0 14 3 True =AVERAGE(A14:A15) 15 4 True =AVERAGE(A14:A15) 16 8 False 0 17 9 True =AVERAGE(A17) 18 6 False 0 19 3 True =AVERAGE(A19:A20) 20 2 True =AVERAGE(A19:A20)

<tbody>
</tbody>

Last edited:

Replies
0
Views
189
Replies
11
Views
308
Replies
0
Views
134
Replies
1
Views
140
Replies
1
Views
178

1,196,155
Messages
6,013,759
Members
441,781
Latest member
Gian Carlos

### 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.

### Which adblocker are you using?

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

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