PC Review


Reply
Thread Tools Rate Thread

Counting Colours

 
 
TJ
Guest
Posts: n/a
 
      21st Feb 2007
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      21st Feb 2007
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
>
>
>

 
Reply With Quote
 
JE McGimpsey
Guest
Posts: n/a
 
      21st Feb 2007
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 <(E-Mail Removed)>,
"TJ" <(E-Mail Removed)> 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

 
Reply With Quote
 
merjet
Guest
Posts: n/a
 
      21st Feb 2007
Erase ".Selection". By the way ColorIndex 1 is black, ColorIndex 3 is
red.

Hth,
Merjet


 
Reply With Quote
 
TJ
Guest
Posts: n/a
 
      21st Feb 2007
Thanks guys
"TJ" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
JE McGimpsey
Guest
Posts: n/a
 
      21st Feb 2007
That's absolutely true only for the default color palette. Palette
colors can be changed.

In article <(E-Mail Removed)>,
"merjet" <(E-Mail Removed)> wrote:

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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting Colours Darren Microsoft Excel Programming 3 24th Sep 2009 12:48 PM
Counting Colours in Excel Carla Microsoft Excel New Users 2 22nd Apr 2008 08:59 PM
Counting cell colours =?Utf-8?B?amMxMzI1Njg=?= Microsoft Excel Worksheet Functions 4 13th Nov 2007 05:22 AM
Counting colours robo Microsoft Excel Worksheet Functions 2 5th Aug 2007 07:43 PM
Counting colours robo Microsoft Excel Misc 1 5th Aug 2007 06:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:08 PM.