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

Hi

I am trying to write a short piece of code that loops through a number of
cells in a given row and increments a counter depending on what colour the
interior of the cell is. I am using the following code

For vC = 10 To 100
With Worksheets("Closed Issues").Cells(vC, 6)
Select Case (.Selection.Interior.ColorIndex)
Case 6 'Yellow
vYellow = vYellow + 1
Case 1 'Red
vRed = vRed + 1
End Select
End With
Next

but keep getting error 438 'Object doe not support this method or property'.
Can anyone see a reason why this is happening or suggest a solution?
Thanks
TJ


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Counting Colours

Remove the selection part in your Select Case:

For vC = 10 To 100
With Worksheets("Closed Issues").Cells(vC, 6)
Select Case (.Interior.ColorIndex)
Case 6 'Yellow
vYellow = vYellow + 1
Case 1 'Red
vRed = vRed + 1
End Select
End With
Next

--
Regards,
Tom Ogilvy


"TJ" wrote:

Hi

I am trying to write a short piece of code that loops through a number of
cells in a given row and increments a counter depending on what colour the
interior of the cell is. I am using the following code

For vC = 10 To 100
With Worksheets("Closed Issues").Cells(vC, 6)
Select Case (.Selection.Interior.ColorIndex)
Case 6 'Yellow
vYellow = vYellow + 1
Case 1 'Red
vRed = vRed + 1
End Select
End With
Next

but keep getting error 438 'Object doe not support this method or property'.
Can anyone see a reason why this is happening or suggest a solution?
Thanks
TJ



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Counting Colours

The Cells() object doesn't have a .Selection Property.

Try:

For vC = 10 To 100
With Worksheets("Closed Issues").Cells(vC, 6)
Select Case (.Interior.ColorIndex)
Case 6 'Yellow
vYellow = vYellow + 1
Case 1 'Red
vRed = vRed + 1
End Select
End With
Next

But the With doesn't really make anything more efficient since it's
inside the loop and is executed every time. Better:

With Worksheets("Closed Issues")
For vC = 10 To 100
Select Case (.Cells(vC, 6).Interior.ColorIndex)
Case 6 'Yellow
vYellow = vYellow + 1
Case 1 'Red
vRed = vRed + 1
End Select
Next
End With

In article ,
"TJ" wrote:

Hi

I am trying to write a short piece of code that loops through a number of
cells in a given row and increments a counter depending on what colour the
interior of the cell is. I am using the following code

For vC = 10 To 100
With Worksheets("Closed Issues").Cells(vC, 6)
Select Case (.Selection.Interior.ColorIndex)
Case 6 'Yellow
vYellow = vYellow + 1
Case 1 'Red
vRed = vRed + 1
End Select
End With
Next

but keep getting error 438 'Object doe not support this method or property'.
Can anyone see a reason why this is happening or suggest a solution?
Thanks
TJ

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Counting Colours

Erase ".Selection". By the way ColorIndex 1 is black, ColorIndex 3 is
red.

Hth,
Merjet


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Counting Colours

Thanks guys
"TJ" wrote in message
...
Hi

I am trying to write a short piece of code that loops through a number of
cells in a given row and increments a counter depending on what colour the
interior of the cell is. I am using the following code

For vC = 10 To 100
With Worksheets("Closed Issues").Cells(vC, 6)
Select Case (.Selection.Interior.ColorIndex)
Case 6 'Yellow
vYellow = vYellow + 1
Case 1 'Red
vRed = vRed + 1
End Select
End With
Next

but keep getting error 438 'Object doe not support this method or
property'. Can anyone see a reason why this is happening or suggest a
solution?
Thanks
TJ





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Counting Colours

That's absolutely true only for the default color palette. Palette
colors can be changed.

In article . com,
"merjet" wrote:

Erase ".Selection". By the way ColorIndex 1 is black, ColorIndex 3 is
red.

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
Counting Colours in Excel Carla New Users to Excel 2 April 22nd 08 08:59 PM
Counting Cells with specific Colours davethewelder Excel Discussion (Misc queries) 10 March 3rd 08 05:09 PM
Counting cell colours jc132568 Excel Worksheet Functions 4 November 13th 07 05:22 AM
Counting colours robo Excel Worksheet Functions 2 August 5th 07 07:43 PM
Counting colours robo Excel Discussion (Misc queries) 1 August 5th 07 06:39 PM


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