![]() |
mixed formatting in same cell with VBA
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. |
mixed formatting in same cell with VBA
You sure you wouldn't want spaces between each part of the name?
In any case, maybe this'll give you a start: Option Explicit Private Sub CommandButton1_Click() With Worksheets("sheet1").Range("a1") .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 |
mixed formatting in same cell with VBA
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 |
mixed formatting in same cell with VBA
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 |
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 |
All times are GMT +1. The time now is 02:32 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com