#1   Report Post  
Posted to microsoft.public.excel.misc
AOP AOP is offline
external usenet poster
 
Posts: 23
Default SUMIF by colour?

Where do I place this code and what else do I need to do for it to work?

Function SumIfByColor(InRange As Range, _
WhatColorIndex As Integer, SumRange As Range, _
Optional OfText As Boolean = False) As Variant
'
' This function will return the SUM of the values of cells in
' SumRange where the corresponding cell in InRange has a background
' color (or font color, if OfText is true) equal to WhatColorIndex.
'
Dim OK As Boolean
Dim Ndx As Long

Application.Volatile True

If (InRange.Rows.Count < SumRange.Rows.Count) Or _
(InRange.Columns.Count < SumRange.Columns.Count) Then
SumIfByColor = CVErr(xlErrRef)
Exit Function
End If

For Ndx = 1 To InRange.Cells.Count
If OfText = True Then
OK = (InRange.Cells(Ndx).Font.ColorIndex = WhatColorIndex)
Else
OK = (InRange.Cells(Ndx).Interior.ColorIndex = WhatColorIndex)
End If
If OK And IsNumeric(SumRange.Cells(Ndx).Value) Then
SumIfByColor = SumIfByColor + SumRange.Cells(Ndx).Value
End If
Next Ndx

End Function
--
AOP
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default SUMIF by colour?

Place the code in a regular code module. See

http://www.mvps.org/dmcritchie/excel/getstarted.htm

if you're not familiar with macros.

For it to work, you need to call the function, say

=SumIfByColor(A:A, 3, B:B, True)

to sum by the font color red (in the default palette).

In article ,
AOP wrote:

Where do I place this code and what else do I need to do for it to work?

Function SumIfByColor(InRange As Range, _
WhatColorIndex As Integer, SumRange As Range, _
Optional OfText As Boolean = False) As Variant
'
' This function will return the SUM of the values of cells in
' SumRange where the corresponding cell in InRange has a background
' color (or font color, if OfText is true) equal to WhatColorIndex.
'
Dim OK As Boolean
Dim Ndx As Long

Application.Volatile True

If (InRange.Rows.Count < SumRange.Rows.Count) Or _
(InRange.Columns.Count < SumRange.Columns.Count) Then
SumIfByColor = CVErr(xlErrRef)
Exit Function
End If

For Ndx = 1 To InRange.Cells.Count
If OfText = True Then
OK = (InRange.Cells(Ndx).Font.ColorIndex = WhatColorIndex)
Else
OK = (InRange.Cells(Ndx).Interior.ColorIndex = WhatColorIndex)
End If
If OK And IsNumeric(SumRange.Cells(Ndx).Value) Then
SumIfByColor = SumIfByColor + SumRange.Cells(Ndx).Value
End If
Next Ndx

End Function

  #3   Report Post  
Posted to microsoft.public.excel.misc
AOP AOP is offline
external usenet poster
 
Posts: 23
Default SUMIF by colour?

At the moment I have column E with running total of column D. I have
conditional formatted column E for all cells under the total of 100 to turn
yellow. That works fine. What I need with this code is to sum all values in
col D that are opposite the yellow cells. Something like this:

D E
2 2
1 3
1 4
3 7
and so on

How do I do that?
--
AOP


"JE McGimpsey" wrote:

Place the code in a regular code module. See

http://www.mvps.org/dmcritchie/excel/getstarted.htm

if you're not familiar with macros.

For it to work, you need to call the function, say

=SumIfByColor(A:A, 3, B:B, True)

to sum by the font color red (in the default palette).

In article ,
AOP wrote:

Where do I place this code and what else do I need to do for it to work?

Function SumIfByColor(InRange As Range, _
WhatColorIndex As Integer, SumRange As Range, _
Optional OfText As Boolean = False) As Variant
'
' This function will return the SUM of the values of cells in
' SumRange where the corresponding cell in InRange has a background
' color (or font color, if OfText is true) equal to WhatColorIndex.
'
Dim OK As Boolean
Dim Ndx As Long

Application.Volatile True

If (InRange.Rows.Count < SumRange.Rows.Count) Or _
(InRange.Columns.Count < SumRange.Columns.Count) Then
SumIfByColor = CVErr(xlErrRef)
Exit Function
End If

For Ndx = 1 To InRange.Cells.Count
If OfText = True Then
OK = (InRange.Cells(Ndx).Font.ColorIndex = WhatColorIndex)
Else
OK = (InRange.Cells(Ndx).Interior.ColorIndex = WhatColorIndex)
End If
If OK And IsNumeric(SumRange.Cells(Ndx).Value) Then
SumIfByColor = SumIfByColor + SumRange.Cells(Ndx).Value
End If
Next Ndx

End Function


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,268
Default SUMIF by colour?

You don't need any UDF for that, just use SUMIF and the same criteria that
you used for the formatting

=SUMIF(E:E,"<100",D:D)

or if you are using a cell where you put 100

=SUMIF(E:E,"<"&G2,D:D)

where G2 would be the


--


Regards,


Peo Sjoblom



"AOP" wrote in message
...
At the moment I have column E with running total of column D. I have
conditional formatted column E for all cells under the total of 100 to
turn
yellow. That works fine. What I need with this code is to sum all values
in
col D that are opposite the yellow cells. Something like this:

D E
2 2
1 3
1 4
3 7
and so on

How do I do that?
--
AOP


"JE McGimpsey" wrote:

Place the code in a regular code module. See

http://www.mvps.org/dmcritchie/excel/getstarted.htm

if you're not familiar with macros.

For it to work, you need to call the function, say

=SumIfByColor(A:A, 3, B:B, True)

to sum by the font color red (in the default palette).

In article ,
AOP wrote:

Where do I place this code and what else do I need to do for it to
work?

Function SumIfByColor(InRange As Range, _
WhatColorIndex As Integer, SumRange As Range, _
Optional OfText As Boolean = False) As Variant
'
' This function will return the SUM of the values of cells in
' SumRange where the corresponding cell in InRange has a background
' color (or font color, if OfText is true) equal to WhatColorIndex.
'
Dim OK As Boolean
Dim Ndx As Long

Application.Volatile True

If (InRange.Rows.Count < SumRange.Rows.Count) Or _
(InRange.Columns.Count < SumRange.Columns.Count) Then
SumIfByColor = CVErr(xlErrRef)
Exit Function
End If

For Ndx = 1 To InRange.Cells.Count
If OfText = True Then
OK = (InRange.Cells(Ndx).Font.ColorIndex = WhatColorIndex)
Else
OK = (InRange.Cells(Ndx).Interior.ColorIndex = WhatColorIndex)
End If
If OK And IsNumeric(SumRange.Cells(Ndx).Value) Then
SumIfByColor = SumIfByColor + SumRange.Cells(Ndx).Value
End If
Next Ndx

End Function




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I save new colour schemes for graphs in the colour template Alison Charts and Charting in Excel 1 July 22nd 06 10:35 PM
can the fill colour of a bar be tied to the data font colour data PaulC Charts and Charting in Excel 0 June 23rd 06 01:21 AM
change a cell background colour to my own RGB colour requirements Stephen Doughty Excel Discussion (Misc queries) 4 June 16th 06 01:08 PM
SUMIF - Range name to used for the "sum_range" portion of a SUMIF function Oscar Excel Worksheet Functions 2 January 11th 05 11:01 PM
Text in Blue colour, but print in black colour wuwu Excel Worksheet Functions 1 November 13th 04 02:36 PM


All times are GMT +1. The time now is 01:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"