Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Old April 2nd 08, 08:00 PM posted to microsoft.public.excel.misc
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 577
Default Concatenate and maintain format of original cells

How can concatenate from multiple cells and maintain the format of the
original cells? For an example; I'd like to join two cells together where
the 1st cell has bold font and the 2nd cell is italic and both cells has a
different font size.

  #2   Report Post  
Old April 2nd 08, 08:11 PM posted to microsoft.public.excel.misc
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 6,582
Default Concatenate and maintain format of original cells

You can't do this and maintain formula links to the individual cells.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Scott" wrote in message
...
How can concatenate from multiple cells and maintain the format of the
original cells? For an example; I'd like to join two cells together where
the 1st cell has bold font and the 2nd cell is italic and both cells has a
different font size.



  #3   Report Post  
Old April 2nd 08, 08:52 PM posted to microsoft.public.excel.misc
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 5,651
Default Concatenate and maintain format of original cells

On Wed, 2 Apr 2008 12:00:00 -0700, Scott
wrote:

How can concatenate from multiple cells and maintain the format of the
original cells? For an example; I'd like to join two cells together where
the 1st cell has bold font and the 2nd cell is italic and both cells has a
different font size.


In Excel, you can only have differential formatting of an actual text string,
not of strings produced by formulas.

So the only way you could do this would be with a macro.

You could use an event driven macro to obtain the font characteristics you want
to apply to the different parts of the resultant string. You'll have to
determine which cells will be the Source and which the Destination within the
macro. I just hard-coded A1:A2 to be the source and C1 to be the destination
in this example.

Right-click on the sheet tab and select View Code.

Paste the code below into the window that opens.

Whenever you change your selection, whatever is in A1 & A2, along with the font
characteristics of size, italic and bold, will be concatenated and placed in
C1. You can change the range; and also change, or increase, the number of font
properties you wish to check for. (Be sure to change lNumOfFontProps
accordingly, also)

================================
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rSrc As Range
Dim rDest As Range
Dim c As Range
Dim sTemp As String
Dim sFmt()
Dim i As Long, j As Long
Application.ScreenUpdating = False

Set rSrc = Range("A1:A2")
Set rDest = Range("C1")

Const lNumOfFontProps As Long = 3

ReDim sFmt(0 To rSrc.Count - 1, 0 To lNumOfFontProps)

i = 0
For Each c In rSrc
sTemp = sTemp & c.Text 'may need to use Value if LEN255
sFmt(i, 0) = Len(c.Text) 'length of string
sFmt(i, 1) = c.Font.Bold
sFmt(i, 2) = c.Font.Italic
sFmt(i, 3) = c.Font.Size
'add more depending on font properties required
i = i + 1
Next c

j = 1
With rDest
..Value = sTemp
For i = 0 To UBound(sFmt, 1)
With .Characters(j, sFmt(i, 0))
.Font.Bold = sFmt(i, 1)
.Font.Italic = sFmt(i, 2)
.Font.Size = sFmt(i, 3)
End With
j = j + sFmt(i, 0)
Next i
End With

Application.ScreenUpdating = True
End Sub
================================

--ron
  #4   Report Post  
Old April 3rd 18, 11:23 PM posted to microsoft.public.excel.misc
external usenet poster
 
First recorded activity by ExcelBanter: Apr 2018
Posts: 1
Default Concatenate and maintain format of original cells

On Wednesday, April 2, 2008 at 1:52:49 PM UTC-6, Ron Rosenfeld wrote:
On Wed, 2 Apr 2008 12:00:00 -0700, Scott
wrote:

How can concatenate from multiple cells and maintain the format of the
original cells? For an example; I'd like to join two cells together where
the 1st cell has bold font and the 2nd cell is italic and both cells has a
different font size.


In Excel, you can only have differential formatting of an actual text string,
not of strings produced by formulas.

So the only way you could do this would be with a macro.

You could use an event driven macro to obtain the font characteristics you want
to apply to the different parts of the resultant string. You'll have to
determine which cells will be the Source and which the Destination within the
macro. I just hard-coded A1:A2 to be the source and C1 to be the destination
in this example.

Right-click on the sheet tab and select View Code.

Paste the code below into the window that opens.

Whenever you change your selection, whatever is in A1 & A2, along with the font
characteristics of size, italic and bold, will be concatenated and placed in
C1. You can change the range; and also change, or increase, the number of font
properties you wish to check for. (Be sure to change lNumOfFontProps
accordingly, also)

================================
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rSrc As Range
Dim rDest As Range
Dim c As Range
Dim sTemp As String
Dim sFmt()
Dim i As Long, j As Long
Application.ScreenUpdating = False

Set rSrc = Range("A1:A2")
Set rDest = Range("C1")

Const lNumOfFontProps As Long = 3

ReDim sFmt(0 To rSrc.Count - 1, 0 To lNumOfFontProps)

i = 0
For Each c In rSrc
sTemp = sTemp & c.Text 'may need to use Value if LEN255
sFmt(i, 0) = Len(c.Text) 'length of string
sFmt(i, 1) = c.Font.Bold
sFmt(i, 2) = c.Font.Italic
sFmt(i, 3) = c.Font.Size
'add more depending on font properties required
i = i + 1
Next c

j = 1
With rDest
.Value = sTemp
For i = 0 To UBound(sFmt, 1)
With .Characters(j, sFmt(i, 0))
.Font.Bold = sFmt(i, 1)
.Font.Italic = sFmt(i, 2)
.Font.Size = sFmt(i, 3)
End With
j = j + sFmt(i, 0)
Next i
End With

Application.ScreenUpdating = True
End Sub
================================

--ron


Hi Ron,

How would I do this if I wanted A1 and B1 to be the range, and C1 the result? And then dragged down throughout my sheet (A2 and B2 into C2, etc).
  #5   Report Post  
Old August 5th 20, 05:49 PM posted to microsoft.public.excel.misc
external usenet poster
 
First recorded activity by ExcelBanter: Aug 2020
Posts: 1
Default Concatenate and maintain format of original cells

On Tuesday, April 3, 2018 at 11:23:34 PM UTC+1, wrote:
On Wednesday, April 2, 2008 at 1:52:49 PM UTC-6, Ron Rosenfeld wrote:
On Wed, 2 Apr 2008 12:00:00 -0700, Scott
wrote:

How can concatenate from multiple cells and maintain the format of the
original cells? For an example; I'd like to join two cells together where
the 1st cell has bold font and the 2nd cell is italic and both cells has a
different font size.


In Excel, you can only have differential formatting of an actual text string,
not of strings produced by formulas.

So the only way you could do this would be with a macro.

You could use an event driven macro to obtain the font characteristics you want
to apply to the different parts of the resultant string. You'll have to
determine which cells will be the Source and which the Destination within the
macro. I just hard-coded A1:A2 to be the source and C1 to be the destination
in this example.

Right-click on the sheet tab and select View Code.

Paste the code below into the window that opens.

Whenever you change your selection, whatever is in A1 & A2, along with the font
characteristics of size, italic and bold, will be concatenated and placed in
C1. You can change the range; and also change, or increase, the number of font
properties you wish to check for. (Be sure to change lNumOfFontProps
accordingly, also)

================================
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rSrc As Range
Dim rDest As Range
Dim c As Range
Dim sTemp As String
Dim sFmt()
Dim i As Long, j As Long
Application.ScreenUpdating = False

Set rSrc = Range("A1:A2")
Set rDest = Range("C1")

Const lNumOfFontProps As Long = 3

ReDim sFmt(0 To rSrc.Count - 1, 0 To lNumOfFontProps)

i = 0
For Each c In rSrc
sTemp = sTemp & c.Text 'may need to use Value if LEN255
sFmt(i, 0) = Len(c.Text) 'length of string
sFmt(i, 1) = c.Font.Bold
sFmt(i, 2) = c.Font.Italic
sFmt(i, 3) = c.Font.Size
'add more depending on font properties required
i = i + 1
Next c

j = 1
With rDest
.Value = sTemp
For i = 0 To UBound(sFmt, 1)
With .Characters(j, sFmt(i, 0))
.Font.Bold = sFmt(i, 1)
.Font.Italic = sFmt(i, 2)
.Font.Size = sFmt(i, 3)
End With
j = j + sFmt(i, 0)
Next i
End With

Application.ScreenUpdating = True
End Sub
================================

--ron


Hi Ron,

How would I do this if I wanted A1 and B1 to be the range, and C1 the result? And then dragged down throughout my sheet (A2 and B2 into C2, etc).


Hi Ron,

Thank you for that and wow.

Just wondering how do you do it for multiple rows?

Kind regards

Dean


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
Losing Original Cell Format when pasting in cells mrbill Excel Discussion (Misc queries) 1 December 10th 06 05:10 PM
Maintain Format of Pivot Table Cash Excel Discussion (Misc queries) 1 March 30th 06 07:23 PM
Maintain mutliple original formats in a formula result KeLee Excel Worksheet Functions 2 February 20th 06 01:50 AM
How do I concatenate text to keep the text's original color/font/s Temp_User Excel Discussion (Misc queries) 1 September 12th 05 10:12 PM
How do I maintain format of worksheets when combining several? OC Excel Worksheet Functions 3 June 26th 05 04:10 PM


All times are GMT +1. The time now is 02:22 PM.

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

About Us

"It's about Microsoft Excel"

 

Copyright © 2017