+ Reply to Thread
Results 1 to 6 of 6

Preserve Existing Text Formatting When Updating / Adding More Text?

  1. #1
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 365
    Posts
    202

    Preserve Existing Text Formatting When Updating / Adding More Text?

    I am writing a macro to automate the updating of text records. For example, in an existing file I have a text record (in a single cell) like:
    Please Login or Register  to view this content.
    and in a separate file containing today's updates, the corresponding record says:
    Please Login or Register  to view this content.
    I want to add the new information to the existing record in my existing file (which is pretty simple). But the problem is that I manually highlight certain text in my existing file (in bold red text) like this:
    Please Login or Register  to view this content.
    and when I use a macro to concatenate that existing text with the (new) added text from the other file, my manually-highlighted text gets set back to plain (black) text. So instead of this:
    Please Login or Register  to view this content.
    I get this (red highlighting gone):
    Please Login or Register  to view this content.
    Is there any way for a macro to append new text into an existing cell, while retaining whatever individual font modifications exist within the original text?

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Preserve Existing Text Formatting When Updating / Adding More Text?

    You can use code like this.

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 365
    Posts
    202

    Re: Preserve Existing Text Formatting When Updating / Adding More Text?

    I tried:
    Please Login or Register  to view this content.
    where OldLength is the length of the existing text in cell B3, and AddedText is a string variable containing the new text to add. I get:
    Please Login or Register  to view this content.
    Last edited by Merf; 08-04-2017 at 11:54 AM. Reason: Typo

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Preserve Existing Text Formatting When Updating / Adding More Text?

    This worked for me
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 365
    Posts
    202

    Re: Preserve Existing Text Formatting When Updating / Adding More Text?

    Why did you use the Text property (rather than just the length of range B4), and why did you add 1 to the existing length?
    Please Login or Register  to view this content.
    I tried your latest suggestion and I still get the same error message. Running Excel 2016 by the way.
    I really appreciate the help, just isn't working for me for some reason!

  6. #6
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 365
    Posts
    202

    Re: Preserve Existing Text Formatting When Updating / Adding More Text?

    Ran some more tests and discovered what I think is the root of my problem. My initial example above was simplified. The actual text I am trying to manipulate is >255 characters. I ran a test with less than 255 characters, and got things to work OK. But if the original text is greater than 255 characters, it doesn't work. I'm no longer getting the error 1004 message (???), the macro runs OK but the original text remains unchanged (if it's >255 characters). So looks like I'm out of luck...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 04-05-2016, 03:03 PM
  2. How to preserve text formatting
    By dstin44 in forum Excel General
    Replies: 3
    Last Post: 11-07-2015, 03:17 PM
  3. [SOLVED] adding text in front of potentially existing text (in 1 cell) with IF/THEN statement
    By Marijke in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-10-2014, 04:20 AM
  4. Preserve formatting in existing file when refreshing from external source
    By justmatt in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-23-2012, 01:57 AM
  5. Change cell text and preserve text formatting
    By migi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-19-2011, 08:50 AM
  6. Adding text to the end of existing string / text.
    By DTK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-30-2010, 02:51 AM
  7. adding text to existing text in whole coulumn
    By mrwhitee in forum Excel General
    Replies: 2
    Last Post: 08-30-2005, 07:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1