+ Reply to Thread
Results 1 to 7 of 7

Delete red text within selected cells and add space if there isn't one

  1. #1
    Registered User
    Join Date
    12-24-2019
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Delete red text within selected cells and add space if there isn't one

    Hello,

    I have found a VBA code on the Internet that deletes all red and size 1 characters within selected cells.

    The code looks like this:
    Please Login or Register  to view this content.
    Could anybody help me change the code so that it adds a space if it deletes something in the middle of the cell (provided there's no space to the left or to the right of the deleted text)?

    For example if you look at this picture:

    asddf.png

    After running the current code, A2 will look like A3. Sometimes I have spaces there, but the color of the space may be set to red and will be deleted too, so A1 might also look like A3 after running the code. In both cases I would like the code to add a space there so that the result would be "word1 word2 ".

    Important information:

    - the space that I would like to be added should have the same size as the character before the deleted part
    - the formatting of the rest of the cell shouldn't be affected

    Thank you very much in advance for your help.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,368

    Re: Delete red text within selected cells and add space if there isn't one

    You could use " " instead of "", that is, a single space instead of null. Then use Trim to remove excess spaces.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    12-24-2019
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: Delete red text within selected cells and add space if there isn't one

    Thank you for your answer, but unfortunately I can't do that as Trim will change the formatting of the cell.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Delete red text within selected cells and add space if there isn't one

    Try
    Please Login or Register  to view this content.
    Last edited by jindon; 07-06-2020 at 07:14 AM.

  5. #5
    Registered User
    Join Date
    12-24-2019
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: Delete red text within selected cells and add space if there isn't one

    jindon: Thank you for your help, I appreciate it a lot. It works great, but the only problem is that the size of the space is the same as the size of the deleted text, rather than the character before it. Which means if it deletes some text in the middle that has size 1, then the space will be there, but won't be visible.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Delete red text within selected cells and add space if there isn't one

    Then try add one line
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-24-2019
    Location
    UK
    MS-Off Ver
    2016
    Posts
    7

    Re: Delete red text within selected cells and add space if there isn't one

    jindon: Thank you so much for your help! It works like a charm.

+ 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. [SOLVED] Replace and delete certain text in the selected cells
    By Dunno123 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-06-2020, 06:37 PM
  2. [SOLVED] VBA - delete text b/w first and second space in a string of text - apply to selected range
    By mgerner in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-16-2018, 03:52 PM
  3. Delete Characters Before Last Space In Text String [SOLVED]
    By alacey425 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-01-2016, 11:30 PM
  4. Loop backwards through selected range - delete entire row from selected cells
    By scottbass in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-20-2014, 09:21 AM
  5. Replies: 2
    Last Post: 08-28-2011, 02:39 AM
  6. Excel 2007 : Howto delete an empty space in cells
    By Doggen in forum Excel General
    Replies: 1
    Last Post: 02-02-2011, 04:48 AM
  7. Delete space in Text
    By herve in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-04-2005, 03:05 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