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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Wulf

Active Member
Joined
Dec 1, 2004
Messages
395
Office Version
  1. 365
Platform
  1. Windows
You just do that in the 'Home' tab. Type as you would in Word.
 
Upvote 0

Rhinoman

New Member
Joined
Aug 9, 2016
Messages
14
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

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
18,069
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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

Rhinoman

New Member
Joined
Aug 9, 2016
Messages
14
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

JeanKim

Board Regular
Joined
May 31, 2016
Messages
183
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,191,213
Messages
5,985,303
Members
439,956
Latest member
FrazzledCat

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