Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How to preserve character formatting in a cell

I need to add and remove characters from the end of cells in an
existing worksheet. Some of the existing characters in the cells have
character formats like bold or italic.
The problem is that I cannot find a way to preserve the existing
character formatting in the cells. The following example will lose all
character formats in a cell.
ActiveCell.Value = ActiveCell.Value & "@"
It is easy to do by hand but it seems impossible through VBA.
Is there an easy way of preserving the existing character formats?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default How to preserve character formatting in a cell

this doesn't change formatting for me, unless i'm missing something. if it's
bold, it stays bold, if it's bold and italic, it stays bold and italic.
ActiveCell.Value = ActiveCell.Value & "@"


--


Gary


"Kobus" wrote in message
ups.com...
I need to add and remove characters from the end of cells in an
existing worksheet. Some of the existing characters in the cells have
character formats like bold or italic.
The problem is that I cannot find a way to preserve the existing
character formatting in the cells. The following example will lose all
character formats in a cell.
ActiveCell.Value = ActiveCell.Value & "@"
It is easy to do by hand but it seems impossible through VBA.
Is there an easy way of preserving the existing character formats?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default How to preserve character formatting in a cell

Funny. Like Gary said, works for me too.
Try a work around by copying the cell and pasting the formats:

ActiveCell.Copy
ActiveCell.Value = ActiveCell.Value & "@"
ActiveCell.PasteSpecial xlPasteFormats

Sharad

"Kobus" wrote in message
ups.com...
I need to add and remove characters from the end of cells in an
existing worksheet. Some of the existing characters in the cells have
character formats like bold or italic.
The problem is that I cannot find a way to preserve the existing
character formatting in the cells. The following example will lose all
character formats in a cell.
ActiveCell.Value = ActiveCell.Value & "@"
It is easy to do by hand but it seems impossible through VBA.
Is there an easy way of preserving the existing character formats?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to preserve character formatting in a cell

the OP is talking about Rich Text formatting, where individual characters
within the cell have different formatting. Some individual characters may
be bold, but not all characters are bold for example. This certainly
exhibits the behavior the OP described.

--
Regards,
Tom Ogilvy


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this doesn't change formatting for me, unless i'm missing something. if
it's bold, it stays bold, if it's bold and italic, it stays bold and
italic.
ActiveCell.Value = ActiveCell.Value & "@"


--


Gary


"Kobus" wrote in message
ups.com...
I need to add and remove characters from the end of cells in an
existing worksheet. Some of the existing characters in the cells have
character formats like bold or italic.
The problem is that I cannot find a way to preserve the existing
character formatting in the cells. The following example will lose all
character formats in a cell.
ActiveCell.Value = ActiveCell.Value & "@"
It is easy to do by hand but it seems impossible through VBA.
Is there an easy way of preserving the existing character formats?





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to preserve character formatting in a cell

Assuming Rich Text Formatting as you describe:

This example maintains the bold and Italic character formatting. You would
need to add an array for each formatting attribute you want to maintain :

Sub AppendData()
Dim rng As Range, l As Long
Dim i As Long, arrBold() As Variant
Dim arrItalic As Variant
Set rng = ActiveCell
l = Len(rng)
ReDim arrBold(1 To l)
ReDim arrItalic(1 To l)
' Capture the formatting
For i = 1 To l
arrBold(i) = rng.Characters(i, 1).Font.Bold
arrItalic(i) = rng.Characters(i, 1).Font.Italic
Next
rng.Value = rng.Value & "@"
For i = 1 To l
rng.Characters(i, 1).Font.Bold = arrBold(i)
rng.Characters(i, 1).Font.Italic = arrItalic(i)
Next
End Sub

--
Regards,
Tom Ogilvy



"Kobus" wrote in message
ups.com...
I need to add and remove characters from the end of cells in an
existing worksheet. Some of the existing characters in the cells have
character formats like bold or italic.
The problem is that I cannot find a way to preserve the existing
character formatting in the cells. The following example will lose all
character formats in a cell.
ActiveCell.Value = ActiveCell.Value & "@"
It is easy to do by hand but it seems impossible through VBA.
Is there an easy way of preserving the existing character formats?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default How to preserve character formatting in a cell

Right Tom!, That explains it.

"Tom Ogilvy" wrote in message
...
the OP is talking about Rich Text formatting, where individual characters
within the cell have different formatting. Some individual characters may
be bold, but not all characters are bold for example. This certainly
exhibits the behavior the OP described.

--
Regards,
Tom Ogilvy


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this doesn't change formatting for me, unless i'm missing something. if
it's bold, it stays bold, if it's bold and italic, it stays bold and
italic.
ActiveCell.Value = ActiveCell.Value & "@"


--


Gary


"Kobus" wrote in message
ups.com...
I need to add and remove characters from the end of cells in an
existing worksheet. Some of the existing characters in the cells have
character formats like bold or italic.
The problem is that I cannot find a way to preserve the existing
character formatting in the cells. The following example will lose all
character formats in a cell.
ActiveCell.Value = ActiveCell.Value & "@"
It is easy to do by hand but it seems impossible through VBA.
Is there an easy way of preserving the existing character formats?







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How to preserve character formatting in a cell

On Mar 17, 7:47 pm, "Sharad" wrote:
Right Tom!, That explains it.

"Tom Ogilvy" wrote in message

...



the OP is talking about Rich Text formatting, where individual characters
within the cell have different formatting. Some individual characters may
be bold, but not all characters are bold for example. This certainly
exhibits the behavior the OP described.


--
Regards,
Tom Ogilvy


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this doesn't change formatting for me, unless i'm missing something. if
it's bold, it stays bold, if it's bold and italic, it stays bold and
italic.
ActiveCell.Value = ActiveCell.Value & "@"


--


Gary


"Kobus" wrote in message
roups.com...
I need to add and remove characters from the end of cells in an
existing worksheet. Some of the existing characters in the cells have
character formats like bold or italic.
The problem is that I cannot find a way to preserve the existing
character formatting in the cells. The following example will lose all
character formats in a cell.
ActiveCell.Value = ActiveCell.Value & "@"
It is easy to do by hand but it seems impossible through VBA.
Is there an easy way of preserving the existing character formats?- Hide quoted text -


- Show quoted text -


Thank you. I think Tom got a solution. Lets hope that the only
formatting is bold and italic. I presume it would be difficult to
check for all formatting (such as colours, underline subscript,
superscipt, caps, etc.).
I was hoping that VBA would have a more elegant solution.

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
cell formatting in excel - more than 1 character at a time patgo37 Excel Discussion (Misc queries) 0 February 19th 10 12:09 AM
Excel 2007 - Formatting text in cell (character by character) TomC Excel Discussion (Misc queries) 0 January 29th 10 07:25 PM
formatting colour in cells when one cell contains a character wilko[_2_] Excel Worksheet Functions 1 September 14th 09 01:27 AM
Preserve cell formatting as SSN danhattan Excel Discussion (Misc queries) 2 August 30th 07 05:36 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 09:44 AM.

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

About Us

"It's about Microsoft Excel"