Link to home
Start Free TrialLog in
Avatar of hindersaliva
hindersalivaFlag for United Kingdom of Great Britain and Northern Ireland

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?

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

Open in new window

SOLUTION
Avatar of Roy Cox
Roy Cox
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hindersaliva

ASKER

ActiveCell for testing Roy. Yes I'll post a workbook later today.
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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Pleased to help