Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default SumByCellColor

Anyone an idea why my function does not work... it seems to unload...

Public Function SumByCellColor(Cellrange As range, Cellcolor As Single) As Single
Application.Volatile
n = 0
For Each RangeCell In Cellrange
If RangeCell.Interior.ColorIndex = Cellcolor Then
If IsNumeric(RangeCell.Value) Then n = n + RangeCell.Value
End If
Next SumByCellColor = n
End Function

Thx in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default SumByCellColor

"SIGE" skrev i melding
om...
Anyone an idea why my function does not work... it seems to unload...

Public Function SumByCellColor(Cellrange As range, Cellcolor As Single) As

Single
Application.Volatile
n = 0
For Each RangeCell In Cellrange


n and RangeCell are not declared

Next SumByCellColor = n


This can't do any good.
Also, coloring doesn't trig a calculation, you need an F9 or similar to make
a recalculation happen.

HTH. Best wishes Harald


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default SumByCellColor

This works for me

Public Function SumByCellColor(Cellrange As range, Cellcolor As Single) As
Single
Application.Volatile
n = 0
For Each RangeCell In Cellrange
If RangeCell.Interior.ColorIndex = Cellcolor Then
If IsNumeric(RangeCell.Value) Then n = n + RangeCell.Value
End If
Next
SumByCellColor = n
End Function

Also, see

http://www.xldynamic.com/source/xld.ColourCounter.html

--

HTH

RP

"SIGE" wrote in message
om...
Anyone an idea why my function does not work... it seems to unload...

Public Function SumByCellColor(Cellrange As range, Cellcolor As Single) As

Single
Application.Volatile
n = 0
For Each RangeCell In Cellrange
If RangeCell.Interior.ColorIndex = Cellcolor Then
If IsNumeric(RangeCell.Value) Then n = n + RangeCell.Value
End If
Next SumByCellColor = n
End Function

Thx in advance



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default SumByCellColor

"Harald Staff" wrote in message ...
"SIGE" skrev i melding
om...
Anyone an idea why my function does not work... it seems to unload...

Public Function SumByCellColor(Cellrange As range, Cellcolor As Single) As

Single
Application.Volatile
n = 0
For Each RangeCell In Cellrange


n and RangeCell are not declared

Next SumByCellColor = n


This can't do any good.
Also, coloring doesn't trig a calculation, you need an F9 or similar to make
a recalculation happen.

HTH. Best wishes Harald


Hi Guys,

Thx for the advises. I surely had my Variables declared.
It works fine... except with "conditional formatting"...
Why is this?
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default SumByCellColor

Colors produced with conditional formatting do not change the Colorindex
property - in fact, there is no property that reflects if conditional
formatting is currently being applied or which condition. You have to check
the condition that conditional formatting is using. Chip Pearson has
written a complex function that does this, but If you know the condition I
would just use that. If curious about Chip's approach

http://www.cpearson.com/excel.htm

go to the page index and look at the entries for conditional formatting.

--
Regards,
Tom Ogilvy

"SIGE" wrote in message
om...
"Harald Staff" wrote in message

...
"SIGE" skrev i melding
om...
Anyone an idea why my function does not work... it seems to unload...

Public Function SumByCellColor(Cellrange As range, Cellcolor As

Single) As
Single
Application.Volatile
n = 0
For Each RangeCell In Cellrange


n and RangeCell are not declared

Next SumByCellColor = n


This can't do any good.
Also, coloring doesn't trig a calculation, you need an F9 or similar to

make
a recalculation happen.

HTH. Best wishes Harald


Hi Guys,

Thx for the advises. I surely had my Variables declared.
It works fine... except with "conditional formatting"...
Why is this?



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



All times are GMT +1. The time now is 07:06 PM.

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

About Us

"It's about Microsoft Excel"