Get ColorIndex from Character in String

J

JasonH

Hi All,
Could anyone help solve this problem I have?
I need to determine the colorIndex of a character from a string stored
in a cell.
I can call the characters one by one, and there seems to be a
..font.colorIndex method but I can not seem to store the value.

Here is the code I'm trying.


Sub ColourAndReportCaharcter()
Dim i, j As Integer
Dim N As Variant
j = ActiveCell.Characters.Count
For i = 1 To j
N = ActiveCell.Characters(i).Font.ColorIndex 'This Fails? Why?
Debug.Print TypeName(N) ' TypeName is 'ERROR"
Next i
End Sub


Thanks for any help.
Jason
 
G

GS

Firstly, colorindex values are type 'Long' and so your code would print
"Long" in the debug window regardless of the character's color.

Secondly, the first line of code that fails is where you try to put the
Character.Count value into 'j'.

Try this revised code. (I renamed it with the correct spelling of the
word "Character", and so it shouldn't raise an alert when you run it)

Sub ColourAndReportCharacter()
Dim i As Integer
For i = 1 To Len(ActiveCell.Text)
Debug.Print ActiveCell.Characters(i).Font.ColorIndex
Next i
End Sub

So how, exactly, do you want to store the ColorIndex values? I suggest
you play around with colors and see the output in the Immediate Window.
 

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