ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Font color setting problem (https://www.excelbanter.com/excel-programming/387649-font-color-setting-problem.html)

[email protected]

Font color setting problem
 

I am trying to set the color of a range of cells based on the number
of a looping variable (Count). The following code gives me an
error indicating that the color can't be set using a variable name.
What would be an alternate way to do this?


For Count = 1 To 60

Sheets("Sheet3").Select
Range("B5").Select
Selection.Font.ColorIndex = Count

Thanks.


JLGWhiz

Font color setting problem
 
The ColorPalette for ColorIndex only has 56 colors. This will change so fast
that you will only see the first and last colors.

For Count = 1 To 56

Sheets("Sheet3").Range("B5").Font.ColorIndex = Count
Count = Count + 1
Next

" wrote:


I am trying to set the color of a range of cells based on the number
of a looping variable (Count). The following code gives me an
error indicating that the color can't be set using a variable name.
What would be an alternate way to do this?


For Count = 1 To 60

Sheets("Sheet3").Select
Range("B5").Select
Selection.Font.ColorIndex = Count

Thanks.



PCLIVE

Font color setting problem
 
This is because the color index only goes up to 56. The error occurs when
you're trying to set the index to 57.

See here.
http://www.mvps.org/dmcritchie/excel...htm#colorindex


wrote in message
ups.com...

I am trying to set the color of a range of cells based on the number
of a looping variable (Count). The following code gives me an
error indicating that the color can't be set using a variable name.
What would be an alternate way to do this?


For Count = 1 To 60

Sheets("Sheet3").Select
Range("B5").Select
Selection.Font.ColorIndex = Count

Thanks.




Vergel Adriano

Font color setting problem
 
I believe there are only 56 colors. To see all of them:

Sub test()
For Count = 1 To 56
Sheets("Sheet3").Select
Range("B" & Count + 4).Interior.ColorIndex = Count
Next Count
End Sub





--
Hope that helps.

Vergel Adriano


" wrote:


I am trying to set the color of a range of cells based on the number
of a looping variable (Count). The following code gives me an
error indicating that the color can't be set using a variable name.
What would be an alternate way to do this?


For Count = 1 To 60

Sheets("Sheet3").Select
Range("B5").Select
Selection.Font.ColorIndex = Count

Thanks.



geofflilley

Font color setting problem
 

;7516647 Wrote:
I am trying to set the color of a range of cells based on the number
of a looping variable (Count). The following code gives me an
error indicating that the color can't be set using a variable name.
What would be an alternate way to do this?


For Count = 1 To 60

Sheets("Sheet3").Select
Range("B5").Select
Selection.Font.ColorIndex = Count

Thanks.


I think what you probably want to do is something like this:

Sub setColor()
Sheets("Sheet1").Select
Range("B5").Select
For Count = 0 To 56
Selection.Font.ColorIndex = Count
ActiveCell.Offset(1, 0).Activate
Next
End Sub

Problem is that the colors only go up to 56. I suspect the error that
you're getting is "unable to set colorindex property of the Font class."
That's kinda misleading. You CAN use the counter as you outlined
above; the problem is that you're asking the code to set the ColorIndex
to a number that it can't do.

HTH

Cheers
Geoff


--
geofflilley


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com