Format only part of a cell

Rhinoman

New Member
Joined
Aug 9, 2016
Messages
14
I am trying to format only part of a cell using either formulae or VBA. Any help would be appreciated!

Specifically I need to bold everything but italicize only the text between the parentheses but no formatting to the preceeding text or the parentheses themselves. e.g. "12 (34)"

Thanks!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
You just do that in the 'Home' tab. Type as you would in Word.
 
Upvote 0
You just do that in the 'Home' tab. Type as you would in Word.

Sorry I should have mentioned that I do not want to have to do it manually because I am importing a large number of cells like this and they are not already formatted in this way (they are just regular font).
 
Upvote 0
Sorry I should have mentioned that I do not want to have to do it manually because I am importing a large number of cells like this and they are not already formatted in this way (they are just regular font).
Select the cells you want to format with your mouse, then run the code below.
Code:
Sub Rhinoman()
'Select cells first, then run this macro
Dim c As Range, First As Long, Last As Long
Application.ScreenUpdating = False
For Each c In Selection
    For i = 1 To Len(c.Value)
        If Mid(c.Value, i, 1) = "(" Then
            First = i + 1
        ElseIf Mid(c.Value, i, 1) = ")" Then
            Last = i - 1
            c.Font.Bold = True
            c.Characters(First, Last - First + 1).Font.Italic = True
        End If
    Next i
Next c
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Select the cells you want to format with your mouse, then run the code below.
Code:
Sub Rhinoman()
'Select cells first, then run this macro
Dim c As Range, First As Long, Last As Long
Application.ScreenUpdating = False
For Each c In Selection
    For i = 1 To Len(c.Value)
        If Mid(c.Value, i, 1) = "(" Then
            First = i + 1
        ElseIf Mid(c.Value, i, 1) = ")" Then
            Last = i - 1
            c.Font.Bold = True
            c.Characters(First, Last - First + 1).Font.Italic = True
        End If
    Next i
Next c
Application.ScreenUpdating = True
End Sub

Works great! Thank you so much! I learn something new every day.
 
Upvote 0
My version in case you are interested.
very simple to edit to your need IMO.
Code:
Sub Macro1()
Dim r As Range
Set r = Range("A1:B4")
For Each c In r
    With c.Characters(Start:=1, Length:=Len(c)).Font
        .FontStyle = "Bold"
    End With
    With c.Characters(Start:=InStr(c, "(") + 1, Length:=InStr(c, ")") - InStr(c, "(") - 1).Font
        .FontStyle = "Regular"
        .FontStyle = "Italic"
    End With
Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,447
Members
448,966
Latest member
DannyC96

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