Check if more than one font is used in a cell?

H

Handler Robert

Is there a way to find out, if more than one font is used in a cell?

The example below shows how to use different fonts in one cell.
I need to test if this is done and if it is done to get the differen
font objects.

Range("B5").Select
ActiveCell.FormulaR1C1 = "abcdef"
With ActiveCell.Characters(Start:=1, Length:=2).Font
.Superscript = False
End With
With ActiveCell.Characters(Start:=3, Length:=1).Font
.Superscript = True
End With
With ActiveCell.Characters(Start:=4, Length:=3).Font
.Superscript = False
End With
Range("B6").Selec
 
V

Vic Eldridge

You'd need to loop through all the characters using the Characters object.
The following code should get you started.


For i = 1 To Range("B5").Characters.Count
With Range("B5").Characters(i, 1).Font
MsgBox "Character " & vbTab & .Parent.Text & vbCrLf & _
"Color " & vbTab & .Color & vbCrLf & _
"Bold " & vbTab & .Bold & vbCrLf & _
"Superscript " & vbTab & .Superscript & vbCrLf & _
"Name " & vbTab & .Name
'etc
End With
Next i


Regards,
Vic Eldridge
 
D

Dave Peterson

Just to check to see if there's more than one Font:

Option Explicit

Sub testme01()

Dim myFont As Variant
myFont = ActiveSheet.Range("a1").Font.Name
If IsNull(myFont) Then
MsgBox "multiple fonts"
Else
MsgBox "only one and it's: " & myFont
End If

End Sub

Not sure what you're doing, but here's a link that may give you an idea:

http://www.google.com/[email protected]
 
H

Handler Robert

Thanks for your answers.

With a combinatin of your answers,
I can first check, If a cell contains multiple fonts
and if yes, i have to check each character
 

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