• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Formatting within a cell (Bold, unbold)

ThrottleWorks

Excel Ninja
Hi,

I have a value in say cell A1, value is Yamaha count is 1,000.00.
Now I want this value to be presented in following manner.

Yamaha count is 1,000.00

I want to highlight Yamaha part only, is it possible, I have 5-6 such names, such as BMW, Audi, Benz, Suzuki, if these words are in a cell, I want to format them as BOLD, is it possible.

Can anyone please help me in this.
 
Hi !

Try this demonstration !​
Code:
Sub CellInitialize(Rg As Range)
    With Rg(1)
        .Clear
        .Value = "Yamaha count is 1,000.00"
    End With
End Sub

Sub Demo()
    CellInitialize [A1]
    [A1].Characters(1, Len(Split([A1].Value)(0))).Font.Bold = True
End Sub
Done just using Macro recorder as you can try yourself …
 
Simple brute force method. Might be slower. Search items in column B and data in Column A.
Code:
Public Sub PartialFormat()
Dim rngList As Range, rng As Range
Set rngList = Range("B1:B" & Range("B" & Rows.Count).End(xlUp).Row)
For i = 1 To Range("A" & Rows.Count).End(xlUp).Row
    For Each rng In rngList
        If InStr(1, Range("A" & i).Value, rng.Value, vbTextCompare) > 0 Then
            For j = 1 To Len(Range("A" & i).Value)
                If LCase(Mid(Range("A" & i).Value, j, Len(rng.Value))) = LCase(rng.Value) Then
                    Range("A" & i).Characters(j, Len(rng.Value)).Font.Bold = True
                End If
            Next
        End If
    Next
Next
End Sub
 
Back
Top