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

ajjava

New Member
Joined
Dec 11, 2018
Messages
48
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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
8,107
Office Version
  1. 365
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

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,126
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
4,142
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
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,186,676
Messages
5,959,150
Members
438,399
Latest member
jsparrow22

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
Top