Formatting particular character in a string

smartkrips

New Member
Joined
Aug 20, 2013
Messages
20
Hello Friends,

Is it possible to format particular character in a string...

For example: String = Pipe Sleeve I|32/19

i want to find character '|' in a string and make it bold and red in color...

Like: Pipe Sleeve I|32/19

w/o using Micro?

if not, may I get micro example, please?


Rgds,
KK
 

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.
Hi KK

No, to format the character you must do it manually or run a macro.

For ex., assuming there may be several "|" characters in a cell, this would do it for A1:A10.

Code:
Sub PipeStrong()
Dim r As Range, rC As Range
Dim j As Long, k As Long
Const sPipe As String = "|"

Set r = Range("A1:A10")

For Each rC In r
    k = 1
    Do While True
        j = InStr(k, rC.Value, sPipe)
        If j = 0 Then Exit Do
        With rC.Characters(j, 1).Font
            .Bold = True
            .Color = vbRed
        End With
        k = j + 1
    Loop
Next rC
End Sub
 
Upvote 0
Hello PGC,

Thanks for your answer and macro too...

This really helps and problem solved. :)


Rgds,
KK
 
Last edited:
Upvote 0
You're welcome. Thanks for the feedback.

Remark: I forgot to say in my post that I assumed the text in the cell is a constant, not the result of a formula.
 
Upvote 0

Forum statistics

Threads
1,223,276
Messages
6,171,140
Members
452,381
Latest member
Nova88

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