Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Help - macro messes up the character formating

Greetings,

I need help with a macro.

I use this macro in Excel 2007:

Sub ReplaceTags2()
For Each c In ActiveCell.CurrentRegion.Cells
c.Value = Application.WorksheetFunction.Substitute(c, "####", Chr(10)
& Chr(10))
Next
End Sub

My data contains the markers ####, which I want to replace with
linebreaks.

The macro does its work but messes up the formatting in the cells. I
uploaded the file "Book1.xlsm" he http://www.box.net/shared/8rdsg533qp

The file contains a sample of the data + the macro itself.

Can anyone help me modify the macro to do the replacement without
changing anything to the cell formatting?
Thanks in advance!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Help - macro messes up the character formating

On Fri, 5 Feb 2010 02:42:55 -0800 (PST), Ivaylo
wrote:

Greetings,

I need help with a macro.

I use this macro in Excel 2007:

Sub ReplaceTags2()
For Each c In ActiveCell.CurrentRegion.Cells
c.Value = Application.WorksheetFunction.Substitute(c, "####", Chr(10)
& Chr(10))
Next
End Sub

My data contains the markers ####, which I want to replace with
linebreaks.

The macro does its work but messes up the formatting in the cells. I
uploaded the file "Book1.xlsm" he http://www.box.net/shared/8rdsg533qp

The file contains a sample of the data + the macro itself.

Can anyone help me modify the macro to do the replacement without
changing anything to the cell formatting?
Thanks in advance!


If you don't get a response, post more data here in text form. Many of us will
not upload unsolicited files from the web for fear of infection.
--ron
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Help - macro messes up the character formating

Ok, Ron.

It's a dictionary database which need to be manipulated in Excel

Column A contains words. Column B contains a longer text which
contains formatting like bold, italic, underline, and some words in
color.

When I run the macro, it replaces the markers #### with a linebreak
[Chr(10)]. However, the formatting in column B is messed up - no
italic, no bold, very often the whole text is in some of the color
that some of the words had before running the macro - e.g. red, blue,
etc.

I'd like to replace my markup symbol (####) with a linebreak and
preserving the formatting of the cell contents as is.

Any idea how to modify the macro to do this?

On Feb 5, 1:16*pm, Ron Rosenfeld wrote:
On Fri, 5 Feb 2010 02:42:55 -0800 (PST), Ivaylo
wrote:





Greetings,


I need help with a macro.


I use this macro in Excel 2007:


Sub ReplaceTags2()
For Each c In ActiveCell.CurrentRegion.Cells
c.Value = Application.WorksheetFunction.Substitute(c, "####", Chr(10)
& Chr(10))
Next
End Sub


My data contains the markers ####, which I want to replace with
linebreaks.


The macro does its work but messes up the formatting in the cells. I
uploaded the file "Book1.xlsm" hehttp://www.box.net/shared/8rdsg533qp


The file contains a sample of the data + the macro itself.


Can anyone help me modify the macro to do the replacement without
changing anything to the cell formatting?
Thanks in advance!


If you don't get a response, post more data here in text form. *Many of us will
not upload unsolicited files from the web for fear of infection.
--ron


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Help - macro messes up the character formating

On Fri, 5 Feb 2010 05:11:44 -0800 (PST), Ivaylo
wrote:

Ok, Ron.

It's a dictionary database which need to be manipulated in Excel

Column A contains words. Column B contains a longer text which
contains formatting like bold, italic, underline, and some words in
color.

When I run the macro, it replaces the markers #### with a linebreak
[Chr(10)]. However, the formatting in column B is messed up - no
italic, no bold, very often the whole text is in some of the color
that some of the words had before running the macro - e.g. red, blue,
etc.

I'd like to replace my markup symbol (####) with a linebreak and
preserving the formatting of the cell contents as is.

Any idea how to modify the macro to do this?


Given the information you've provided:

Differential formatting of characters within a cell in Excel can only be done
if the contents is a text string. So I will assume that the contents of Column
B is a text string, and not the results of a formula, or a picture, or
something else.

That being the case, because of the way Excel does this process, I don't
believe you can merely do the substitution. I believe you will need to do the
substitution, and then reformat the characters as they were before.

So you will probably need to modify your macro to look at each character in
sequence, obtain the font characteristics that might be different, and then
write the string back into the cell with the substitution made and the
appropriate formatting.
--ron
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
Sort messes up pictures hdille Excel Discussion (Misc queries) 1 March 23rd 10 12:00 PM
Search and Replace a Spacific Character with Conditional Formating Dallas Excel Programming 15 December 15th 08 09:11 PM
Date Formating and building character strings C Brandt Excel Discussion (Misc queries) 5 August 18th 07 03:39 AM
auto-filter messes up the formulas Drew2006 Excel Discussion (Misc queries) 1 September 6th 06 08:58 AM
Character formating for User defined function problem RosH Excel Programming 5 December 26th 05 05:46 PM


All times are GMT +1. The time now is 09:03 PM.

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"