A
AnExpertNovice
This code was executed twice. Both times in the immediate pane to ensure
that nothing in my code was generating this error. Here are the results.
(There should be 3 rows. The first row is the executed code and the next
two rows are the resulting output.)
?"idx:" & Range("B5").font.colorindex & " (ThisWorkbook.colors(32) = &H" &
Hex(ThisWorkbook.colors(32))& " clr:&H" & Hex(Range("B5").font.color)
idx:32 (ThisWorkbook.colors(32) = &HFF clr:&HFF
idx:32 (ThisWorkbook.colors(32) = &HFF clr:&HFF0000
ColorIndex 32 was set to red and that is what is displayed in Patterns and
Font. Then the font color in cell B5 was set using index 32. (This is the
bottom right of the palette displaying all 56 colors.)
The first time the code is executed the font color of cell "B5" is reported
as if it were Blue (&HFF0000). Second, and subsequent, executions correctly
report the font color as Red (&H0000FF).
This error can be repeated by selecting the worksheet (using Alt-Tab or any
other method) and then reselecting the VB code window.
Executing this statement reports the same color both times. Thus, the
workaround is not simply referencing the value twice.
...........?Range("B5").font.color & Range("B5").font.color
Is there a workaround or am I "missing" the logic for this problem?
==== Why ColorIndex 32 is being used
============================================
Here is the situation. A worksheet allows the selection of three font
colors and the font color will be used to interpret what the entry means.
So, if the user decides to use Black for two or three of the fonts I need to
modify the font slightly so they see their chosen color. If the font colors
did not need to be unique there would be no issue. Luckily, no one is likely
to detect the difference between 3 cells where the three cells contain text
with a font color of &H0, &H1, and &H2, yet the program can detect the
difference.
To impact the workbook colors ColorIndex 30, 31, and 32 were chosen to hold
the three font colors. These indexes are the last three cells on the last
row of the full palette. They are not normally seen when using the drop
down font selection.
When they change the font color on the color selection worksheet the code
checks all three font colors and ensures they are unique. If not, then one
or two are changed in such a way as to change the font color by 1 unless all
three were chosen to be either black or white. Then one of the colors must
be changed by a value of 2.
Once the colors are verified to be unique, their respective ColorIndex is
set to the chosen color, then the cells where the user chooses the font
color are set to match it's respective ColorIndex.
The problem is that the program was changing the colors! I assumed it was
an error until the problem could be replicated using the code shown.
Any suggestions?
that nothing in my code was generating this error. Here are the results.
(There should be 3 rows. The first row is the executed code and the next
two rows are the resulting output.)
?"idx:" & Range("B5").font.colorindex & " (ThisWorkbook.colors(32) = &H" &
Hex(ThisWorkbook.colors(32))& " clr:&H" & Hex(Range("B5").font.color)
idx:32 (ThisWorkbook.colors(32) = &HFF clr:&HFF
idx:32 (ThisWorkbook.colors(32) = &HFF clr:&HFF0000
ColorIndex 32 was set to red and that is what is displayed in Patterns and
Font. Then the font color in cell B5 was set using index 32. (This is the
bottom right of the palette displaying all 56 colors.)
The first time the code is executed the font color of cell "B5" is reported
as if it were Blue (&HFF0000). Second, and subsequent, executions correctly
report the font color as Red (&H0000FF).
This error can be repeated by selecting the worksheet (using Alt-Tab or any
other method) and then reselecting the VB code window.
Executing this statement reports the same color both times. Thus, the
workaround is not simply referencing the value twice.
...........?Range("B5").font.color & Range("B5").font.color
Is there a workaround or am I "missing" the logic for this problem?
==== Why ColorIndex 32 is being used
============================================
Here is the situation. A worksheet allows the selection of three font
colors and the font color will be used to interpret what the entry means.
So, if the user decides to use Black for two or three of the fonts I need to
modify the font slightly so they see their chosen color. If the font colors
did not need to be unique there would be no issue. Luckily, no one is likely
to detect the difference between 3 cells where the three cells contain text
with a font color of &H0, &H1, and &H2, yet the program can detect the
difference.
To impact the workbook colors ColorIndex 30, 31, and 32 were chosen to hold
the three font colors. These indexes are the last three cells on the last
row of the full palette. They are not normally seen when using the drop
down font selection.
When they change the font color on the color selection worksheet the code
checks all three font colors and ensures they are unique. If not, then one
or two are changed in such a way as to change the font color by 1 unless all
three were chosen to be either black or white. Then one of the colors must
be changed by a value of 2.
Once the colors are verified to be unique, their respective ColorIndex is
set to the chosen color, then the cells where the user chooses the font
color are set to match it's respective ColorIndex.
The problem is that the program was changing the colors! I assumed it was
an error until the problem could be replicated using the code shown.
Any suggestions?