Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default 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.

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.misc
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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Formatting; finding numerical data in mixed text. Philonis Excel Discussion (Misc queries) 2 June 5th 07 11:57 PM
Conditional Formatting in for Cells with Mixed Dates and Text M. A. Newcomb Excel Worksheet Functions 1 May 8th 07 10:05 PM
Mixed Cell Formatiing Gene Setting up and Configuration of Excel 5 July 26th 06 04:41 AM
Mixed data types in a cell camell Excel Discussion (Misc queries) 2 March 8th 06 08:36 PM
Mixed Cell prbucci Excel Worksheet Functions 2 January 13th 06 03:04 AM


All times are GMT +1. The time now is 09:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"