How to discovery the color...

L

Lisandro Oliveira

How can I know what is the color of the value of variable?
Example:

Cell A1 = “test†(it’s in red)

VBA:

Dim var as string
Var = range(“A1â€).value

If var.Interior.ColorIndex = red then
Msgbox “redâ€
End if

Tks,
Lisandro
 
T

Tom Ogilvy

for the Font:
Dim r as Range
set r = range(“A1â€)

If r.Font.ColorIndex = 3 then
Msgbox “redâ€
End if

if the cell background is red:

Dim r as Range
set r = range(“A1â€)

If r.Interior.ColorIndex = 3 then
Msgbox “redâ€
End if
 
L

Lisandro Oliveira

Hi Tom,

The fixed color that is returning is "-4105"
Doesn’t matter if it is blue or red, always return "-4105" from
r.Font.ColorIndex

Why??

This is the code:

For i = 0 To UBound(meuarray)
Range("A2").ClearFormats
Range("A2").Value = meuarray(i)
Set test = Range("A2")
If test.Font.ColorIndex = "3" Then
Cells(ll, col + 1).Select
Selection.Font.ColorIndex = 3
End If
Cells(ll, col + 1).Value = meuarray(i)
ll = ll + 1
Next
 
L

Lisandro Oliveira

The problem is that the cell where is the value has more than one value with
different colors.
A1 = "A, B, C"
A = red
B = Blue
C = Black

I put each value in a different cell
C1 = A
D1 = B
E1 = C

But i need to bring also the color each value.
 
T

Tom Ogilvy

that would be the case if your using conditional formatting to apply the
color.


? xlAutomatic
-4105

For conditional formatting, you would have to check the same conditions you
have defined in the conditional formatting to see which condition is true.
There is no way to directly get the color produced by conditional formatting.

You can look at this, but I think you just need to check the condition which
you should know.
http://www.cpearson.com/excel/CFColors.htm
 
T

Tom Ogilvy

if as you seem to say, a single cell has rich text formatting so parts of the
cell are on color and parts another, then I get this:

? activeCell.Font.ColorIndex
Null

not -4105 with is the value for automatic coloring.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top