Bold part of a string

  • Thread starter Thread starter Bill D.
  • Start date Start date
B

Bill D.

I have a string in a cell and I want the first 14 characters to be Bold
and the rest to be the default format. Example:

Customer Name: ABC Company Inc.

Customer Name: should be Bold

The entry is via a UserForm

Private Sub TextBox2_Change()
Range("C6").Font.Bold = True
Range("C6") = "Customer Name: " & TextBox2.Text
End Sub

As it is now, all of the entry is Bold

I believe I need to apply the Left function here.

Bill

There are 10 types of people; those that understand binary and those
that don't.

Remove NOTME to reply direct
 
Private Sub TextBox2_Change()
Range("C6") = "Customer Name: " & TextBox2.Text
Range("C6").Characters(1, 14).Font.Bold = True
End Sub
 
One way:

Const sPrefix As String = "Customer Name: "
With Range("C6")
.Value = sPrefix & TextBox2.Text
.Characters(Len(sPrefix) + 1).Font.Bold = True
End With
 
Private Sub Textbox2_Change()
Range("C6").Value = "Customer Name: " & TextBox2.Text
Range("C6").Font.Bold = False
Range("C6").Characters(1, 14).Font.Bold = True
End Sub

Worked for me.
 
Both JE's and Vasants solutions bolded the whole string but could be fixed
by adding in
Range("C6").Font.Bold = False
before the command containing the characters command.

as I did in mine.

Tested all three in xl2000
 
Oops, wrong part of string. Change

.Characters(Len(sPrefix) + 1).Font.Bold = True

to

.Characters(1,Len(sPrefix)).Font.Bold = True
 
I misread the OP, so mine bolded only the second part (unless you'd
already bolded the first part).
 
Private Sub TextBox2_Change()
Const sPrefix As String = "Customer Name: "
With Range("C6")
.Value = sPrefix & TextBox2.Text
.Characters(1, Len(sPrefix)).Font.Bold = True

End With
End Sub

Bolded the whole cell. I manually unbolded it before showing the userform.

Private Sub TextBox2_Change()
Const sPrefix As String = "Customer Name: "
With Range("C6")
.Value = sPrefix & TextBox2.Text
.Font.Bold = False
.Characters(1, Len(sPrefix)).Font.Bold = True

End With
End Sub

worked for me xl2000

Your code should work, but being in the change event, I believe the
formatting somehow gets transferred to being the default.

Perhaps it works on the MAC. (both were tested in Excel 2000, SR1, under
Windows 2K)
 
Ah, my fault - I didn't put it in the change event. Works the same in
MacXL.

Bug report's in for the next version.
 
Thanks all for your help.

Bill

There are 10 types of people; those that understand binary and those
that don't.

Remove NOTME to reply direct
 
Back
Top