Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default count shaded cells with a gradient fill

Dear Experts:
below macro counts the number of shaded cells in the selection.

I wonder whether the below macro can be re-written to consider
gradient fills as well, i.e. ...
.... e.g. I got a gradient fill with two colors (light blue RGB 220,
230, 242 and dark blue RGB 79, 129, 189), the gradient pattern is
horizontal.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Sub grey_count()
Dim lastcell As Variant
Dim firstcell As Variant
Dim Cell As Range
Dim x As Long
lastcell = Cells.SpecialCells(xlCellTypeLastCell).Address
firstcell = "A1"
Range(firstcell & ":" & lastcell).Select
For Each Cell In Selection
If Cell.Interior.Color = RGB(234, 234, 234) Then x = x + 1
Next
MsgBox x & " cells are grey (234, 234, 234)"
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default count shaded cells with a gradient fill


The easiest way is to check if the cell has shading of any type...
"If ActiveCell.Interior.ColorIndex < xlColorIndexNone Then x = x + 1"
This should work in all xl versions, however, in xl2007+ all color values were changed so you
should thoroughly test it.
--
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware
('Shade Data Rows' the way you want them)



"AndreasHermle"
wrote in message
...
Dear Experts:
below macro counts the number of shaded cells in the selection.

I wonder whether the below macro can be re-written to consider
gradient fills as well, i.e. ...
... e.g. I got a gradient fill with two colors (light blue RGB 220,
230, 242 and dark blue RGB 79, 129, 189), the gradient pattern is
horizontal.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Sub grey_count()
Dim lastcell As Variant
Dim firstcell As Variant
Dim Cell As Range
Dim x As Long
lastcell = Cells.SpecialCells(xlCellTypeLastCell).Address
firstcell = "A1"
Range(firstcell & ":" & lastcell).Select
For Each Cell In Selection
If Cell.Interior.Color = RGB(234, 234, 234) Then x = x + 1
Next
MsgBox x & " cells are grey (234, 234, 234)"
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default count shaded cells with a gradient fill


Actually that should have been "Cell" not "ActiveCell"...
"If Cell.Interior.ColorIndex < xlColorIndexNone Then x = x + 1"




"Jim Cone"
wrote in message
...

The easiest way is to check if the cell has shading of any type...
"If ActiveCell.Interior.ColorIndex < xlColorIndexNone Then x = x + 1"
This should work in all xl versions, however, in xl2007+ all color values were changed so you
should thoroughly test it.
--
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware
('Shade Data Rows' the way you want them)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default count shaded cells with a gradient fill

On Jul 24, 2:12*am, "Jim Cone" wrote:
Actually that should have been "Cell" not "ActiveCell"...
* *"If Cell.Interior.ColorIndex < xlColorIndexNone Then x = x + 1"

"Jim Cone"
wrote in ...









The easiest way is to check if the cell has shading of any type...
* "If ActiveCell.Interior.ColorIndex < xlColorIndexNone Then x = x + 1"
This should work in all xl versions, however, in xl2007+ *all color values were changed so you
should thoroughly test it.
--
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware
('Shade Data Rows' the way you want them)


Hi Jim,

oops, I inadvertently did not give you any feedback to your post.
Sorry about this.

Ok, thank you very much for your valuable and professional help. This
is a very good piece of advice.

Regards, Andreas
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
Formula to count cells that contain a number & are not shaded Thrlckr Excel Discussion (Misc queries) 2 September 26th 06 11:52 PM
how do I count the number of gray-shaded cells within a range? Y Excel Worksheet Functions 4 August 10th 06 11:50 AM
How can I get a count of cells in a range that are shaded a certa. Slinkeysgirl Excel Worksheet Functions 3 April 1st 05 03:53 PM
How do I count shaded cells Randy Excel Worksheet Functions 19 February 3rd 05 11:35 PM
Count number of shaded cells Maddoktor Excel Discussion (Misc queries) 2 December 20th 04 08:35 PM


All times are GMT +1. The time now is 06:53 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"