Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default combine cells and preserve formatting of individual characters

I am trying to create a macro which combines text from multiple cells
into a single cell (simple), but I need to preserve the formatting of
the individual characters. Each cell may contain some characters of
Arial and some characters of Symbol, some itallics, and/or some bold.

How can I manipulate the cell contents without losing the unique
formatting? Is there a way to detect the character formats within a
cell so that I can reapply them after I combine cell values?

Thanks,
Alec



------------------------------------------------
Message posted from the Excel Tip Forum at http://www.ExcelTip.com/forum/

-- View and post usenet messages directly from http://www.ExcelTip.com
-- Hundreds of free MS Excel tips, tricks and solutions
------------------------------------------------
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default combine cells and preserve formatting of individual characters

I am trying to create a macro which combines text from multiple cells
into a single cell (simple), but I need to preserve the formatting of
the individual characters. Each cell may contain some characters of
Arial and some characters of Symbol, some itallics, and/or some bold.

How can I manipulate the cell contents without losing the unique
formatting? Is there a way to detect the character formats within a
cell so that I can reapply them after I combine cell values?


Check the Help for Characters Object.

Try this, albeit not very tight code since I don't know your application
specifics. I have "hardcoded" 3 cells to sum below, and hardcoded only
the 3 properties you indicated would matter.

Sub foobar()
Dim i as long, i1 as long, i2 as long, i3 as long
i1 = Len(Range("Element1"))
i2 = Len(Range("Element2"))
i3 = Len(Range("Element3"))
Range("Concatenated")=Range("Element1") & Range("Element2") &
Range("Element3")
For i = 1 To i1
Range("Concatenated").Characters(i, 1).Font.name =
Range("Element1").Characters(i, 1).Font.name
Range("Concatenated").Characters(i, 1).Font.Bold =
Range("Element1").Characters(i, 1).Font.Bold
Range("Concatenated").Characters(i, 1).Font.Italic =
Range("Element1").Characters(i, 1).Font.Italic
Next
For i = 1 To i2
Range("Concatenated").Characters(i1 + i, 1).Font.name =
Range("Element2").Characters(i, 1).Font.name
Range("Concatenated").Characters(i1 + i, 1).Font.Bold =
Range("Element2").Characters(i, 1).Font.Bold
Range("Concatenated").Characters(i1 + i, 1).Font.Italic =
Range("Element2").Characters(i, 1).Font.Italic
Next
For i = 1 To i3
Range("Concatenated").Characters(i1 + i2 + i, 1).Font.name =
Range("Element3").Characters(i, 1).Font.name
Range("Concatenated").Characters(i1 + i2 + i, 1).Font.Bold =
Range("Element3").Characters(i, 1).Font.Bold
Range("Concatenated").Characters(i1 + i2 + i, 1).Font.Italic =
Range("Element3").Characters(i, 1).Font.Italic
Next
End Sub

The key here was NOT to set the formula for range Concatenated. Do it
in the code, or else Excel will homogenize the font properties.

You can also use With to improve this if you understand how. If you
want to something REALLY advanced, there are gurus here that can give
you the logic to walk through each and every object property (i.e.
Bold,etc.); I'd stick with doing them one by one if it was me.

Shout back here if you need more.
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
hiding individual characters in Excel Anita Stuever Excel Discussion (Misc queries) 7 May 6th 08 10:02 PM
Preserve cell formatting as SSN danhattan Excel Discussion (Misc queries) 2 August 30th 07 05:36 PM
Combine cells with text formatting o1darcie1o Excel Worksheet Functions 3 February 22nd 07 02:02 AM
combine 2 cells but keep formating of each individual cell dwillman Excel Worksheet Functions 3 July 7th 06 10:23 PM
How to preserve formatting with vlookup Mathias Excel Discussion (Misc queries) 2 March 29th 06 10:36 PM


All times are GMT +1. The time now is 07:58 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"