Is there a way to apply Conditional Formatting to JUST a number in a text string?

ajjava

Board Regular
Joined
Dec 11, 2018
Messages
57
Office Version
  1. 365
Platform
  1. Windows
So, in other words:

I have cells that contain text strings.
The text strings may or may not contain numbers.
In the event that they DO contain numbers, I'd like to set up some way to automatically make JUST THE NUMBERS bold. \

Is this possible? Either via Conditional Formatting or VBA?

Thanks!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Not with conditional formatting, but you could use a macro for this.

Select the cells and run this:

Code:
Sub BoldSelectedNumbers()
Dim my_cell, i
For Each my_cell In Selection
    For i = 1 To Len(my_cell.Value)
        If IsNumeric(Mid(my_cell.Value, i, 1)) Then
            my_cell.Characters(i).Font.Bold = True
        Else
            my_cell.Characters(i).Font.Bold = False
        End If
    Next i
Next my_cell
End Sub
 
Upvote 0
Solution
Not with conditional formatting, but you could use a macro for this.

Select the cells and run this:

Rich (BB code):
Sub BoldSelectedNumbers()
Dim my_cell, i
For Each my_cell In Selection
    For i = 1 To Len(my_cell.Value)
        If IsNumeric(Mid(my_cell.Value, i, 1)) Then
            my_cell.Characters(i).Font.Bold = True
        Else
            my_cell.Characters(i).Font.Bold = False
        End If
    Next i
Next my_cell
End Sub
Not necessarily faster, but I like using the Like operator for this...

If Mid(my_cell.Value, i, 1) Like "#" Then
 
Upvote 0
Maybe using the worksheet change event

The example below tracks changes to ant cell from A1 to A10 on the Sheet

Right click the Sheet Tab, Select "View code" and paste the code below in there
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim I As Long
    If Not Intersect(Target, Range("A1:A10")) Is Nothing Then
        For I = 1 To Len(Target)
            If IsNumeric(Mid(Target.Value, I, 1)) Then
                Target.Characters(I, 1).Font.Bold = True
            Else
                Target.Characters(I, 1).Font.Bold = False
            End If
        Next I
    End If
End Sub

Didn't See the other posts when i posted(I guess I had not refreshed the page)---well, I will just keep my solution here :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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