Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default if fill color = this, then increment this cell by one

Here is my first attempt

Private Sub changeColor()
Dim x As Integer
Dim y As Integer
Dim z As Integer


Set myfrange = Sheet1.Range("AI:5").Value = x
Set myyrange = Sheet1.Range("AK:5").Value = y
Set myzrange = Sheet1.Range("AK:5").Value = z


If Range("C4:af5").Cells.Interior.Color.[Red] Then x = x + 1
If Range("C4:af5").Cells.Interior.Color.[Magenta] Then y = y + 1
If Range("C4:af5").Cells.Interior.Color.[Black] Then z = z + 1

This doesn't work. Any ideas?
Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default if fill color = this, then increment this cell by one

hi,
see this site for color indexes. only 7 colors have names. all the other
have index numbers.
http://www.mvps.org/dmcritchie/excel/colors.htm

i have a problem with the Range("C4:AF5").
I hope you haven't scattered these colors throught out the range and are
expecting this code to count all the colors. if so, then you will need a for
next loop to loop through the range and look at each cell color individually.
Post back with more info.

regards
FSt1
"forbes" wrote:

Here is my first attempt

Private Sub changeColor()
Dim x As Integer
Dim y As Integer
Dim z As Integer


Set myfrange = Sheet1.Range("AI:5").Value = x
Set myyrange = Sheet1.Range("AK:5").Value = y
Set myzrange = Sheet1.Range("AK:5").Value = z


If Range("C4:af5").Cells.Interior.Color.[Red] Then x = x + 1
If Range("C4:af5").Cells.Interior.Color.[Magenta] Then y = y + 1
If Range("C4:af5").Cells.Interior.Color.[Black] Then z = z + 1

This doesn't work. Any ideas?
Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default if fill color = this, then increment this cell by one

On Wed, 19 Sep 2007 13:55:09 -0700, forbes
wrote:

Here is my first attempt

Private Sub changeColor()
Dim x As Integer
Dim y As Integer
Dim z As Integer


Set myfrange = Sheet1.Range("AI:5").Value = x
Set myyrange = Sheet1.Range("AK:5").Value = y
Set myzrange = Sheet1.Range("AK:5").Value = z


If Range("C4:af5").Cells.Interior.Color.[Red] Then x = x + 1
If Range("C4:af5").Cells.Interior.Color.[Magenta] Then y = y + 1
If Range("C4:af5").Cells.Interior.Color.[Black] Then z = z + 1

This doesn't work. Any ideas?
Thanks


The syntax is wrong in a few places. Try this:

Private Sub ChangeColor()

Dim MyFRange As Range, MyXRange As Range, MyYRange As Range
Dim rCell As Range

Set MyFRange = Sheet1.Range("AI5")
Set MyXRange = Sheet1.Range("AK5")
Set MyYRange = Sheet1.Range("AM5")

MyFRange.Value = 0: MyXRange.Value = 0: MyYRange.Value = 0

For Each rCell In Sheet1.Range("C4:AF5").Cells
Select Case rCell.Interior.Color
Case vbRed
MyFRange.Value = MyFRange.Value + 1
Case vbMagenta
MyXRange.Value = MyXRange.Value + 1
Case vbBlack
MyYRange.Value = MyYRange.Value + 1
End Select
Next rCell

Set MyFRange = Nothing
Set MyXRange = Nothing
Set MyYRange = Nothing
Set rCell = Nothing

End Sub
--
Dick Kusleika
Microsoft MVP-Excel
http://www.dailydoseofexcel.com
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default if fill color = this, then increment this cell by one

On Sep 19, 5:52 pm, Dick Kusleika wrote:
On Wed, 19 Sep 2007 13:55:09 -0700, forbes
wrote:





Here is my first attempt


Private Sub changeColor()
Dim x As Integer
Dim y As Integer
Dim z As Integer


Set myfrange = Sheet1.Range("AI:5").Value = x
Set myyrange = Sheet1.Range("AK:5").Value = y
Set myzrange = Sheet1.Range("AK:5").Value = z


If Range("C4:af5").Cells.Interior.Color.[Red] Then x = x + 1
If Range("C4:af5").Cells.Interior.Color.[Magenta] Then y = y + 1
If Range("C4:af5").Cells.Interior.Color.[Black] Then z = z + 1


This doesn't work. Any ideas?
Thanks


The syntax is wrong in a few places. Try this:

Private Sub ChangeColor()

Dim MyFRange As Range, MyXRange As Range, MyYRange As Range
Dim rCell As Range

Set MyFRange = Sheet1.Range("AI5")
Set MyXRange = Sheet1.Range("AK5")
Set MyYRange = Sheet1.Range("AM5")

MyFRange.Value = 0: MyXRange.Value = 0: MyYRange.Value = 0

For Each rCell In Sheet1.Range("C4:AF5").Cells
Select Case rCell.Interior.Color
Case vbRed
MyFRange.Value = MyFRange.Value + 1
Case vbMagenta
MyXRange.Value = MyXRange.Value + 1
Case vbBlack
MyYRange.Value = MyYRange.Value + 1
End Select
Next rCell

Set MyFRange = Nothing
Set MyXRange = Nothing
Set MyYRange = Nothing
Set rCell = Nothing

End Sub
--
Dick Kusleika
Microsoft MVP-Excelhttp://www.dailydoseofexcel.com- Hide quoted text -

- Show quoted text -


Thanks everyone. Dick, worked perfectly, and Fst1 thanks for the site.
I'll check it out. I don't work with VBA often, but I love the
simplicity of it when I do need it. Thanks again! Forbes

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 fill one cell color with text html/rgb color from another thewris Excel Discussion (Misc queries) 2 January 22nd 09 12:24 AM
Match TextBox Back Color to Cell Fill Color AMY Z. Excel Programming 4 October 12th 06 06:07 PM
Cell Fill Color and text color - changes for recipient Shadowman13 Excel Discussion (Misc queries) 0 March 8th 06 11:32 PM
change fill color of a range of cells based on color of a cell? DarMelNel Excel Programming 0 March 2nd 06 06:35 PM
Set Cell Fill Color Martin Excel Programming 3 September 18th 05 03:38 PM


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