Excel Sum total based on font color, Automatic Black font color creates error while Sum and decimal value not included in sum

Jyotirmaya

Board Regular
Joined
Dec 2, 2015
Messages
204
Office Version
  1. 2019
Platform
  1. Windows
Code:
Public Function ColorSum(ByVal target As Range, ByVal MyColor As String)
Dim Blacksum As Long, Othersum As Long, cel As Range
 Application.Volatile
 
 Blacksum = 0
 Othersum = 0
 For Each cel In target
 If IsNumeric(cel.Value) Then
 If cel.Font.ColorIndex = 1 Then
 Blacksum = Blacksum + cel.Value
 Else
 Othersum = Othersum + cel.Value
 End If
 End If
 Next cel

 ColorSum = IIf(LCase(MyColor) = "black", Blacksum, Othersum)

 End Function


1 . I am using the above code to calculate black colored sum totals and red
colored sum totals in different rows of the excel sheet, but as you know
there is a Automatic black color in Font options, when I am entering
values with that Automatic color ( Black ) it doesn't sum under Black
total, the Automatic Color (Black) cell value's total goes to Red color
total insted of Black color total sum, I want the Automatic Black sum
total should be included on Black sum total.



I am using A11=colorsum(A1:A10,"black")

A11=colorsum(A1:A10,"red")

2. when I am using the code if there is any decimal values such as 1.05+2.00+3.00 the total comes 6 instead of 6.05 when I am format cell numbers to 2 digit still it doesn't shows
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,214,832
Messages
6,121,844
Members
449,051
Latest member
excelquestion515

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