View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default mixed formatting in same cell with VBA

Make sure you adjust the start to add that extra space character, too.

Horatio J. Bilge, Jr. wrote:

Thanks. I've been trying to figure this out for a long time. You're right, I
did have spaces between the values, but I forgot to put them in when I typed
my post...

.Value = Me.txtFirst.Value & " " & Me.txtMiddle.Value & " " & Me.txtLast.Value

"Dave Peterson" wrote:

Just a note, this kind of formatting won't work with formulas and won't work
with numbers. So just in case the user types numbers, it may be best to format
the cells as text before entering the concatenated value into that cell:

Option Explicit
Private Sub CommandButton1_Click()
With Worksheets("sheet1").Range("a1")
.NumberFormat = "@" 'text
.Value = Me.TextBox1.Value & Me.TextBox2.Value & Me.TextBox3.Value
With .Characters(Start:=Len(Me.TextBox1.Value) + 1, _
Length:=Len(Me.TextBox3.Value)).Font
.FontStyle = "Bold"
End With
End With
End Sub

Horatio J. Bilge, Jr. wrote:

Is it possible to have two different text formats in the same cell when using
VBA?

For example, I am using the textboxes from a userform to fill a cell:
WS.Cells(1, 1).Value = Me.txtFirst.Value & Me.txtMiddle.Value &
Me.txtLast.Value

I want to make the font format of one of the values different from the
others. For example, so the end result would be: txtFirst <btxtMiddle</b
txtLast.


--

Dave Peterson


--

Dave Peterson