hindersaliva
asked on
Excel VBA - Highlight specific characters in a string
I have this in a cell formatted Wingdings2 (example)
Activecell.Value = Chr(188) & Chr(189) & Chr(154) & Chr(152)
Edit: It goes that as a UDF ( =GetAttenanceString("C10") for example )
It works OK when the string is actually entered in the cell. Mystery!
Where the character is Chr(154) I want to color it Red. I'm doing it like this. BUT, although the If condition seems to work the entire string is being colored Red, rather than just the Chr(154). What am I missing here please?
Activecell.Value = Chr(188) & Chr(189) & Chr(154) & Chr(152)
Edit: It goes that as a UDF ( =GetAttenanceString("C10")
It works OK when the string is actually entered in the cell. Mystery!
Where the character is Chr(154) I want to color it Red. I'm doing it like this. BUT, although the If condition seems to work the entire string is being colored Red, rather than just the Chr(154). What am I missing here please?
Sub BlankNonAttendingDays()
For iDay = 1 To 7
If Mid(ActiveCell.Value, iDay, 1) = Chr(154) Then
'MsgBox iDay
With ActiveCell.Characters(Start:=iDay, Length:=1).Font
.Size = 11
.Color = 192
End With
End If
Next iDay
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You cannot format the part of the text returned by the formula.
Copy and paste the value in another cell and the same piece of code would work without an issue with the cell with value only.
Copy and paste the value in another cell and the same piece of code would work without an issue with the cell with value only.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Pleased to help
ASKER