how to bold a string variable

Pookiemeister

Active Member
Joined
Nov 26, 2015
Messages
316
Office Version
  1. 365
  2. 2010
I'm probably tired or overthinking this, but how can I bold certain words inside a string or the entire string? Thank you
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,971
To bold the characters in a cell you select cell, and in the edit window select the sub text you want bolded and click the B in the home ribbon.
To do this with code
VBA Code:
Range("A1").Characters(3,4).Font.Bold = True
will make the 3rd, 4rh, 5th and 6th characters in A1 bold.

Note this will not work if the cell holds a formula. The result of formulas are all in the same font.
 

Pookiemeister

Active Member
Joined
Nov 26, 2015
Messages
316
Office Version
  1. 365
  2. 2010
My apologies. I should of explained what I was wanting to achieve much better than how I did.
VBA Code:
    Dim ctrl As MSForms.Control, cf As MSForms.Control
    Dim s As String
    
    For Each ctrl In Me.Controls
        s = ""
        If TypeName(ctrl) = "Frame" Then
            For Each cf In ctrl.Controls
                If "CheckBoxOptionButton" Like "*" & TypeName(cf) & "*" Then If cf.Value Then s = s & cf.Caption & ", "
            Next
          
            Select Case ctrl.Name
                Case Is = "frmTask"
                    If s <> "" Then MsgBox Left(s, Len(s) - 2) & " with " & frmSelectedItem & ";", vbInformation, ctrl.Name
                    If s <> "" Then Cells(lLastRow, "I") = s & "with " & frmSelectedItem & ";"
              
            End Select
        End If
    Next
I am wanting to bold whatever is inside the string "s". How can I do this? Also if you don't mind can you comment the working code given so I can learn from it please and thank you.
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,971
Userform controls do not take rich text. That is, all the characters in any userform control will have the same font.
One cannot bold part of a TextBox.Text or CheckBox.Caption.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,734
Messages
5,626,571
Members
416,192
Latest member
steinach

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