+ Reply to Thread
Results 1 to 7 of 7

Replace all cells with len()=0 to empty strings

  1. #1
    Forum Contributor
    Join Date
    06-18-2012
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    347

    Replace all cells with len()=0 to empty strings

    I made a macro below to replace all cells with len()=0 in the sheet 'ws' to empty strings:

    Please Login or Register  to view this content.
    I noticed that this macro is very slow as the sheet contains nearly 50k rows. Is there a more efficient way?

  2. #2
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,706

    Re: Replace all cells with len()=0 to empty strings

    perhaps something like the below, the null string (FALSE) should be treated as a blank when written back to the worksheet (I.e. COUNTA reverts from 1 to 0)

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    06-18-2012
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    347

    Re: Replace all cells with len()=0 to empty strings

    Many thanks, XLent. Looks very advanced.

  4. #4
    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
    48,120

    Re: Replace all cells with len()=0 to empty strings

    This should be quicker:

    Please Login or Register  to view this content.
    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


  5. #5
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,525

    Re: Replace all cells with len()=0 to empty strings

    Please Login or Register  to view this content.
    Note that typing an empty string is not the same as clearing a cell. Rather, it should be
    Please Login or Register  to view this content.
    Visually, it's kind of the same, but there are situations where Excel is able to see the difference between an empty cell (by ClearContents) and a cell with an empty string typed. And I'm not talking about the fairly common case where after copying formulas that returned empty string and pasting as values, we get a "full" cell, not "empty".

    Artik

  6. #6
    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
    48,120

    Re: Replace all cells with len()=0 to empty strings

    If you type ="" you get a zero length cell value with a formula in it. That's what the code is looking for, and converts it to an empty cell. I couldn't see any difference compared to .ClearContents.

  7. #7
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,525

    Re: Replace all cells with len()=0 to empty strings

    You may not see, but believe me, Excel can see the difference in some cases.
    OK, maybe I overdid it. But ADO sees the difference.

    Artik

+ 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 hyphen instead of empty in empty cells and calculate without error
    By MKLAQ in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-28-2021, 09:06 AM
  2. [SOLVED] Formula to replace cells in range with strings if found
    By JP Romano in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-19-2019, 11:51 AM
  3. [SOLVED] Array of lookups returning multiple strings if last two strings are empty
    By chriskay in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-14-2019, 07:35 AM
  4. Replace Empty Text/Space in all Empty Cells
    By bhenlee in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-04-2018, 10:07 PM
  5. [SOLVED] Find strings within cells and replace with string from a table
    By MMSte in forum Excel General
    Replies: 6
    Last Post: 05-14-2012, 12:22 PM
  6. [SOLVED] Empty cells after assigning C# .NET strings
    By MSH(Matt) in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-15-2005, 11:05 PM
  7. How can I convert empty strings to empty cells?
    By Shane in forum Excel General
    Replies: 2
    Last Post: 07-19-2005, 08:05 AM

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