SUMIF color criteria
Asfero
Posted messages
22
Status
Member
-
Asfero Posted messages 22 Status Member -
Asfero Posted messages 22 Status Member -
Hello,
I would like to use the SUMIF function with the criterion being the color of the numbers.
How should I write it?
=SUMIF(.......)
I want to sum the red numbers from column A1 to A10 for example (only if they are red)
And how do I use a different color that I have defined myself based on RGB???
Thank you
I would like to use the SUMIF function with the criterion being the color of the numbers.
How should I write it?
=SUMIF(.......)
I want to sum the red numbers from column A1 to A10 for example (only if they are red)
And how do I use a different color that I have defined myself based on RGB???
Thank you
Configuration: Windows XP Firefox 3.0.10
13 answers
-
Hello,
Is the red color of your numbers manual or from conditional formatting (following your first post earlier)?
--
Best regards, Michel -
Hello,
It comes from a macro associated with a checkbox. When I check the box, my number turns red. However, I would like to use a different color that I have defined in my color palette.
That's it, and I would like a cell to sum all my numbers for which I have checked the box.
Thank you-
Here are the different color codes used in VBA
https://www.cjoint.com/?fnpWeKdUAL
Could you show your macro, please?
--
Best regards, Michel- Michel
Here is the code for my checkbox
Private Sub CheckBox1_Click()
If Checkbox1.Value = True Then
[F56] = [D56]
[J56].Font.ColorIndex = 3
Else
[F56] = ""
[J56].Font.ColorIndex = 0
End If
End Sub
I would like to sum the cells in J for which I have only checked the box, meaning those that are colored?
So my question is, since I don't know anything about VBA, how do I write the sum formula with a color in number VBA? And then how do I associate this code with the cell where I want the sum to take place?
Thank you for being precise as I really don’t know anything….
-
-
Hello
in Excel
There are no standard formulas that allow you to sum colored cells
However,
You can use VBA
Take a look here for an example
http://bvrve.club.fr/Astuces_Michel/05excelvba.html#Color1
Have a nice day -
Thank you, Mike, but what do I do if I don't want to use red?
How do I write the code?
Michel
Here is the code for my checkbox
Private Sub CheckBox1_Click()
If Checkbox1.Value = True Then
[F56] = [D56]
[J56].Font.ColorIndex = 3
Else
[F56] = ""
[J56].Font.ColorIndex = 0
End If
End Sub
I would like to sum the J cells for which I've only checked the box, so which is the color?
My question is, since I don't know anything about VBA, how do I write the sum formula with a VBA color number? And then how do I associate this code with the cell where I want the sum to happen?
Thank you for being precise because I really don't know anything ....-
Alright!
There are a few small things to improve in your checkbox macro, but it's not a big deal!
The best thing, if you're limited in VBA, would be for you to join the sheet of your workbook with the checkboxes on
https://www.cjoint.com/
and paste the provided link in your message
--
Best regards, Michel -
The problem is that it's not finished. I wanted to understand the principle in order to do the entire table afterwards because I have about a hundred checkboxes to make.
Is there really no code you can write for me with an example of color and box that I could adjust later?
If I have the code written, I could manage, but I need an example with several cells and a color in numbers for VBA.
Let's say I want to sum the cells A56 to J56 among which the numbers are brown color 53.
Thank you for your help. -
Re,
Here is a function that automatically calculates the sum of the "marron53"
Function additionner_marron(plage As Range) Dim cellule As Range, total As Double For Each cellule In plage If cellule.Font.ColorIndex = 53 Then total = total + cellule End If Next additionner_marron = total End Function
Installation:
You need to copy-paste it into a VBE module. You can find out how to do it in the "tips" section of CCM written by our friend gbinforme (it's indeed your article gbinforme, thank you)
http://www.commentcamarche.net/faq/sujet 8130 updating a procedure or function in vba
Then
Insert - Functions - Custom Functions, click on "additionner_marron" and select the range
(A56:J56) in your message
Checkboxes:
I need to search in my attic for a technique for the 100 Checkboxes; so probably tomorrow...
--
Best regards, Michel -
Good evening,
I had prepared something but Michel was faster than me...
I'll share it anyway and besides, it spares me from the detailed explanations he just provided you.
The difference with Michel's macro is that, to allow for more flexibility given your indecision about colors, you can define it in a cell. And Michel made you a custom function, here it's a macro to run.
Choose a cell on your sheet, K1 for example, and name your cell Total1 (make sure to respect the capitalization).
Paste this code as Michel explained above:Sub total1() Dim c As Range, tot1 As Double For Each c In [J56:J58] If c.Interior.ColorIndex = Range("Total1").Interior.ColorIndex Then tot1 = tot1 + c.Value End If Next c Range("Total1").Value = tot1 End Sub
Set your background color in K1, run the macro, and the total of the cells (in J56:J58) having the same background color as K1 will be placed in K1.
Example
Eric -
Re, Eric
Ultimately, I gave up the function to go back to 1 parameterized subroutine as the function was triggering every time we checked or unchecked, resulting in aberrant outcomes!
So in module1 we have:Sub additionner_53(plage As String) Dim cellule As Range, total As Double For Each cellule In Range(plage) If cellule.Font.ColorIndex = 53 Then total = total + cellule End If Next Range("K56") = total End Sub
And in modulefeuil1:Private Sub CheckBox1_Click() If CheckBox1 Then [F56] = [D56] [J56].Font.ColorIndex = 53 Else [F56] = "" [J56].Font.ColorIndex = vbnothing End If additionner_53 ("A56:J56") End Sub attached is a demo
https://www.cjoint.com/?fnswKQcqWS
The big job remains the configuration of the 100 Checkboxes but I don’t want to drag you into class modules, Asfero... Unless Eric or someone else knows a trick to do these configurations easily...
--
Best regards, Michel
-
-
no worries, you put the color code corresponding to the desired color
-
To get all the color codes
Run the following macro
Sub Show_Colors()
For i = 1 To 56
Cells(i, 1).Interior.ColorIndex = i
Next i
End Sub -
Hi Mike
here is the code you proposed
Sub TotalisationCouleurRouge()
Set Aselectionner = Application.InputBox _
(prompt:="select the range of cells ", _
Title:=" Range of cells to select", Type:=8)
Aselectionner.Select 'Selecting the desired range
For Each cel In Aselectionner
If cel.Interior.ColorIndex = 3 Then SomRouge = SomRouge + cel
Next cel
MsgBox SomRouge
End Sub
what should I do when it says CouleurRouge
SomRouge ???
and how do I write the range of my cells when it says
"select the range of cells "
" Range of cells to select"
thank you -
During the execution of the macro
You select the cells to be totaled
in this example, you will have a total of the red cells. -
I'm sorry, but I can only provide translations. Please provide the text you would like translated.
-
Listen, apparently you're not following the procedures mentioned in the previous posts.
Don't try to complicate things.
So we're stopping it here!!!
Have a good evening. -
Hi,
what I need is a clear explanation because I know nothing about it, not references to general explanations.
I need to understand with my data, not general data, because I don't know how to write the codes...
that's all -
-
WOAAAAA ok
Thank you both!!!! Unfortunately, I've been short on time these last few days to try all of this.
I appreciate your help and you'll see me again if I haven't managed it hehe.
Thank you so much!!!!!!!!!!