+ Reply to Thread
Results 1 to 3 of 3

Leading Apostrophe, but no change in formating - Visual Basic

  1. #1
    Registered User
    Join Date
    06-11-2012
    Location
    Stoke on Trent
    MS-Off Ver
    Excel 2007
    Posts
    2

    Leading Apostrophe, but no change in formating - Visual Basic

    Hi,

    I'm creating a simple macro that will go through all relevant cells and checks for leading apostrophe -> adds it if it's missing.
    Everything was working fine, but I noticed that my macro changes the formating of whole cell, which is problem.

    For example: This is how my text looks. to -> 'This is how my text looks.
    Even worse, most of my text is color coded - there are links which are blue, content that is red. After running my macro, everything is in color that has a majority.

    I tried to record the macro by manually inserting the apostrophe, but it showed lots of code 'with selection' and then position where red font starts & ends, position where underline starts & ends, etc.

    My question is. Are these informations stored in some variable, so I can add the apostrophe and then color the cell the way it was before?

    Thanks for your help.

  2. #2
    Registered User
    Join Date
    01-19-2009
    Location
    UK
    MS-Off Ver
    2007
    Posts
    60

    Re: Leading Apostrophe, but no change in formating - Visual Basic

    I assume you have your loop set up so I made this subroutine which adds an apostrophe to the beginning of the cell value and retains most of the formatting.

    It stores the font name, size, colour, bold, italic and underline. You can add the subscript and superscript and whatever else you need yourself.

    Please Login or Register  to view this content.
    You can call this in your code like so:

    Please Login or Register  to view this content.
    Hopefully someone rips this to shreds and optimises it or improves it or something, but I hope it helps.
    Last edited by AKK9; 06-11-2012 at 06:00 PM.
    .
    - AKK9 -

  3. #3
    Registered User
    Join Date
    06-11-2012
    Location
    Stoke on Trent
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Leading Apostrophe, but no change in formating - Visual Basic

    Thank you AKK9, you brought me to correct solution

    Yours is working (apart from missing "Next i") but is too slow if I'm checking hunders of cells with hundereds of characters.
    I tried to simplify formating so it only uses different colors and underlines (note underline is always colored)

    and here is my code, if anyone has similiar problem

    Please Login or Register  to view this content.

    Basically I used User defined data type to store different colors of text in a dynamic array. So now it just has to cycle through every character once.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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