ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   code to choose tab color? (https://www.excelbanter.com/excel-programming/403381-code-choose-tab-color.html)

Mekinnik

code to choose tab color?
 
How can I make the following line of code randomly choose the tab color
index? I would like the code automaticlly color the tab not me choose it.

..Tab.ColorIndex = 3

Mekinnik

code to choose tab color?
 
I have tried this line of code I found in the community forums, but it does
not produce random numbers as far as color numbers go, when I reset the the
macro and start again it produces the same number/color. Does anyone have any
suggestions to this problem?

n = Int((54 * Rnd) + 1)
..Tab.ColorIndex = n

"Mekinnik" wrote:

How can I make the following line of code randomly choose the tab color
index? I would like the code automaticlly color the tab not me choose it.

.Tab.ColorIndex = 3


Jim Cone

code to choose tab color?
 
It works for me.

1. Did you specify the sheet?...
Worksheets(1).Tab.ColorIndex = n
2. Are you using Excel 2002 or a later version?
3. Is N declared as a Long?
4. Try using "Randomize" as a single line just before "n =..."
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Mekinnik"
wrote in message
I have tried this line of code I found in the community forums, but it does
not produce random numbers as far as color numbers go, when I reset the the
macro and start again it produces the same number/color. Does anyone have any
suggestions to this problem?

n = Int((54 * Rnd) + 1)
..Tab.ColorIndex = n

"Mekinnik" wrote:

How can I make the following line of code randomly choose the tab color
index? I would like the code automaticlly color the tab not me choose it.

.Tab.ColorIndex = 3



All times are GMT +1. The time now is 05:02 AM.

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