SUMIF Based on Formatting

bjyes1

New Member
Joined
Feb 5, 2008
Messages
9
Can someone give the way to SUMIF a range of numbers based on formatting alone?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Excel formulae cannot see formatting, so it would need VBA.
If that is ok, then you will need to supply more info.
 
Upvote 0
Note that if the formatting you are referring to is the result of "Conditional Formatting", you should be able to apply the same logic to the SUMIF formula as you did in the Conditional Formatting rule to get what you want.

If the formatting is due to manual formatting changes, then you need to use VBA, as Fluff says.
 
Upvote 0
So, VBA would be needed to, say, use the SUMIF formula to sum all cell with a certain format, say with a yellow shade? If so, how complex would the VBA code be? Is there guidance somewhere that helps with writing such code?
 
Upvote 0
I wouldn't recommend it (i.e. vba is the way to go), but for completeness I'll point out that you could (sort of) use a formula approach here.

The technique is outlined here:

https://www.mrexcel.com/forum/excel-questions/20611-info-only-get-cell-arguments.html

..font colour is option 24. Come with some limitations, including:

- there are more font colours available than the 56 this formula will notice
- required file to be saved as xlm so 'feels' like you're using vba anyway

...only really advantage is you can get to what you're after without actually writing any code.
 
Upvote 0
You can go with PaddyD's approach, or you could use a UDF like
Code:
Function bjyes(Rng As Range, Clr As Range) As Double
   Dim Cl As Range
   
   For Each Cl In Rng
      If Cl.Interior.Color = Clr.Interior.Color Then
         bjyes = bjyes + Cl.Value
      End If
   Next Cl
End Function


Book1
ABCD
1WardAltitude
2Blackwater and Hawley65392
3Cove and Southwood64
4Fernhill62
5Knellwood74
6Manor Park101
7North Town71
8North Town93
9Rowhill98
10St John's71
11St Mark's79
12St Mark's70
13Wellington98
14Wellington89
15West Heath61
16Aldridge Central and South162
17Aldridge Central and South161
18Aldridge Central and South165
19Brownhills156
20Brownhills153
Sheet1
Cell Formulas
RangeFormula
D2=bjyes(B2:B20,C2)
 
Upvote 0
You can go with PaddyD's approach, or you could use a UDF like
Code:
Function bjyes(Rng As Range, Clr As Range) As Double
   Dim Cl As Range
   
   For Each Cl In Rng
      If Cl.Interior.Color = Clr.Interior.Color Then
         bjyes = bjyes + Cl.Value
      End If
   Next Cl
End Function

ABCD
1WardAltitude
2Blackwater and Hawley65392
3Cove and Southwood64
4Fernhill62
5Knellwood74
6Manor Park101
7North Town71
8North Town93
9Rowhill98
10St John's71
11St Mark's79
12St Mark's70
13Wellington98
14Wellington89
15West Heath61
16Aldridge Central and South162
17Aldridge Central and South161
18Aldridge Central and South165
19Brownhills156
20Brownhills153

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
D2=bjyes(B2:B20,C2)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
Fluff and PaddyD,

thank you for your suggestions. 'Preciate your taking the time to respond. Both appear to be viable possibilities. Whatever's simplest and works is my motto. Thanks again.

--- bjyes1
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
"Whatever's simplest and works is my motto"

That'll be Fluff's UDF by a long margin ;)
 
Upvote 0

Forum statistics

Threads
1,214,634
Messages
6,120,659
Members
448,975
Latest member
sweeberry

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