PC Review


Reply
Thread Tools Rate Thread

Concatenate and maintain format of original cells

 
 
Scott
Guest
Posts: n/a
 
      2nd Apr 2008
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.
 
Reply With Quote
 
 
 
 
Jon Peltier
Guest
Posts: n/a
 
      2nd Apr 2008
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" <(E-Mail Removed)> wrote in message
news:6744C8AE-F88F-4242-B393-(E-Mail Removed)...
> 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.



 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      2nd Apr 2008
On Wed, 2 Apr 2008 12:00:00 -0700, Scott <(E-Mail Removed)>
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 LEN>255
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: How do I alphabetize & concatenate cells & maintain row integrity Jacob Skaria Microsoft Excel Worksheet Functions 0 25th Nov 2009 03:23 PM
RE: How do I alphabetize & concatenate cells & maintain row integrity DogLover Microsoft Excel Worksheet Functions 0 25th Nov 2009 03:21 PM
How do I alphabetize & concatenate cells & maintain row integrity D_B Microsoft Excel Worksheet Functions 1 25th Nov 2009 03:15 PM
I cannot maintain original format for linked data within word =?Utf-8?B?RGF2aWQ=?= Microsoft Word Document Management 0 28th Jul 2005 04:19 PM
Concatenate multiple docs into one and maintain original headers/footers Mark Parent Microsoft Word Document Management 1 30th Sep 2004 01:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:23 AM.