Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 32
Default Test for shaded cell?

A friend has a worksheet that some cells are shaded, others aren't. The
shaded cells values are to be summed. Right now, he's writing a different
formula for each row of data to calculate the sum of the shaded cells. Is
there any way to test for a shaded cell and only put it's value into the
sum? Somehow to put that in say the first row of the sum column, and then
copy it down?


Thanks!
Shawn

--
Join the newest in Fantasy Sports.

http://www.6FantasySports.com
(this site supports the Victory Junction Gang Camp with a portion of all
proceeds)


  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 73
Default Test for shaded cell?

Shawn, see if this will help

http://www.cpearson.com/excel/colors.htm
--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 97 & 2000
** remove news from my email address to reply by email **

"43fan" wrote in message
...
A friend has a worksheet that some cells are shaded, others aren't. The
shaded cells values are to be summed. Right now, he's writing a different
formula for each row of data to calculate the sum of the shaded cells. Is
there any way to test for a shaded cell and only put it's value into the
sum? Somehow to put that in say the first row of the sum column, and then
copy it down?


Thanks!
Shawn

--
Join the newest in Fantasy Sports.

http://www.6FantasySports.com
(this site supports the Victory Junction Gang Camp with a portion of all
proceeds)




  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,272
Default Test for shaded cell?

Shawn,

It is not easy, but if you input the function supplied at the end, you can
do it with this formula

=SUMPRODUCT(--(ColorIndex(A1:A100)=3))

if you want the text colour, use

=SUMPRODUCT(--(ColorIndex(A1:A100,TRUE)=3))

You could also set another cell, say C1, to the colour red, and test like
this

=SUMPRODUCT(--(ColorIndex(A1:A100)=ColorIndex(C1)))

So in your case, use the final version using a cell that has no shading.


Here's the function

'---------------------------------------------------------------------
Function ColorIndex(rng As Range, _
Optional text As Boolean = False) As Variant
'---------------------------------------------------------------------
' Function: Returns the colorindex of the supplied range
' Synopsis:
' Author: Bob Phillips/Harlan Grove
'
'---------------------------------------------------------------------
Dim cell As Range, row As Range
Dim i As Long, j As Long
Dim iWhite As Long, iBlack As Long
Dim aryColours As Variant

If rng.Areas.Count 1 Then
ColorIndex = CVErr(xlErrValue)
Exit Function
End If

iWhite = WhiteColorindex(rng.Worksheet.Parent)
iBlack = BlackColorindex(rng.Worksheet.Parent)

If rng.Cells.Count = 1 Then
If text Then
aryColours = DecodeColorIndex(rng, True, iBlack)
Else
aryColours = DecodeColorIndex(rng, False, iWhite)
End If

Else
aryColours = rng.Value
i = 0

For Each row In rng.Rows
i = i + 1
j = 0

For Each cell In row.Cells
j = j + 1

If text Then
aryColours(i, j) = DecodeColorIndex(cell, True, iBlack)
Else
aryColours(i, j) = DecodeColorIndex(cell, False, iWhite)
End If

Next cell

Next row

End If

ColorIndex = aryColours

End Function

Private Function WhiteColorindex(oWB As Workbook)
Dim iPalette As Long
WhiteColorindex = 0
For iPalette = 1 To 56
If oWB.Colors(iPalette) = &HFFFFFF Then
WhiteColorindex = iPalette
Exit Function
End If
Next iPalette
End Function

Private Function BlackColorindex(oWB As Workbook)
Dim iPalette As Long
BlackColorindex = 0
For iPalette = 1 To 56
If oWB.Colors(iPalette) = &H0 Then
BlackColorindex = iPalette
Exit Function
End If
Next iPalette
End Function

Private Function DecodeColorIndex(rng As Range, text As Boolean, idx As
Long)
Dim iColor As Long
If text Then
iColor = rng.font.ColorIndex
Else
iColor = rng.Interior.ColorIndex
End If
If iColor < 0 Then
iColor = idx
End If
DecodeColorIndex = iColor
End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"43fan" wrote in message
...
A friend has a worksheet that some cells are shaded, others aren't. The
shaded cells values are to be summed. Right now, he's writing a different
formula for each row of data to calculate the sum of the shaded cells. Is
there any way to test for a shaded cell and only put it's value into the
sum? Somehow to put that in say the first row of the sum column, and then
copy it down?


Thanks!
Shawn

--
Join the newest in Fantasy Sports.

http://www.6FantasySports.com
(this site supports the Victory Junction Gang Camp with a portion of all
proceeds)




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
Shaded cells won't print shaded Linda C Excel Worksheet Functions 4 April 3rd 23 06:59 PM
tell if a cell is shaded pcor New Users to Excel 2 January 7th 09 04:30 PM
shaded cell sumation oldLearner57 Excel Discussion (Misc queries) 2 April 23rd 08 09:52 PM
Show a row shaded when a cell contains certain data Gadgetman Setting up and Configuration of Excel 6 March 3rd 07 04:18 PM
Hide text in shaded cell mmb Excel Worksheet Functions 3 November 3rd 06 04:45 PM


All times are GMT +1. The time now is 06:01 AM.

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"