Is it possible to colour a partial text in VBA???

agasi

New Member
Joined
Nov 22, 2016
Messages
48
Is it possible to change a font colour only for partial texts within the cell?? For example, in cell: PLEASE DO SUBMIT in black font colour. I change SUBMIT to ENTER. So PLEASE DO stay in black font colour but ENTER font colour in RED.


In my current workbook, the vba turns whole texts to Red. PLEASE DO ENTER in red.

<tbody>
</tbody>
 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Sorry.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim theCell As Range
Dim theArea As Range
Dim theColumn As Integer

theColumn = 3

For Each theArea In Target.Areas
For Each theCell In theArea.Cells
If (theCell.Column = theColumn) Then
theCell.Font.ColorIndex = 3
theCell.Font.Bold = True
End If
Next theCell
Next theArea
 
Upvote 0
Try this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C:C")) Is Nothing Then
If Target.Value = "PLEASE DO SUBMIT" Then Target.Font.Color = vbBlack
If Target.Value = "PLEASE DO ENTER" Then
Target.Font.Color = vbBlack
Target.Characters(11, 15).Font.Color = vbRed
End If
End If
End Sub
 
Upvote 0
Another option:-
NB:- Change any word in any cell in "A1:A50", then new Word Font changed to Red font

Code:
Private [COLOR="Navy"]Sub[/COLOR] Worksheet_Change(ByVal Target [COLOR="Navy"]As[/COLOR] Range)
[COLOR="Navy"]Dim[/COLOR] oVal [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] Sp [COLOR="Navy"]As[/COLOR] Variant, oSp [COLOR="Navy"]As[/COLOR] Variant, Lg [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]If[/COLOR] Not Intersect(Range("A1:A50"), Target) [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
oVal = Target
oSp = Split(oVal, " ")
[COLOR="Navy"]With[/COLOR] Application
  .EnableEvents = False
        .Undo
        Sp = Split(Target, " ")
        Target = oVal
        [COLOR="Navy"]For[/COLOR] n = 0 To UBound(Sp)
            [COLOR="Navy"]If[/COLOR] Not Sp(n) = oSp(n) [COLOR="Navy"]Then[/COLOR]
                Target.Characters(Lg + n + 1, Len(oSp(n))).Font.Color = vbRed
                [COLOR="Navy"]Exit[/COLOR] For
            [COLOR="Navy"]End[/COLOR] If
            Lg = Lg + Len(Sp(n))
        [COLOR="Navy"]Next[/COLOR] n
   .EnableEvents = True
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Mick

Apologies. I just gave up on this and did not realise that I have got an answer from you. It is exactly what I need. Really appreciated.
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,031
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top