+ Reply to Thread
Results 1 to 5 of 5

Macro that deletes empty columns but also removes leading zeros

  1. #1
    Registered User
    Join Date
    03-22-2018
    Location
    Taunton, England
    MS-Off Ver
    10
    Posts
    35

    Macro that deletes empty columns but also removes leading zeros

    Hi there

    I have a macro that was created to clean non printing characters and then delete empty columns. The macro does this very well but when it runs it removes the leading zeros from numbers. All cells are formatted as General. Here is the macro for perusal. I cannot attach the worksheet because when I try to anonymise the data the data moves from the left hand side of the cell to the right - although the cell still is formatted as General.

    Please Login or Register  to view this content.
    So I am left with the correct columns with figures missing the leading zero.

    Any takers?

    Many thanks

    Big TP

  2. #2
    Registered User
    Join Date
    02-22-2016
    Location
    Harare, Zimbabwe
    MS-Off Ver
    2007 & 2010
    Posts
    71

    Re: Macro that deletes empty columns but also removes leading zeros

    Try;

    Please Login or Register  to view this content.
    Happy? Click the * to the left.

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro that deletes empty columns but also removes leading zeros

    Or, format the column with zeros as "Text" before you run the code.

  4. #4
    Registered User
    Join Date
    03-22-2018
    Location
    Taunton, England
    MS-Off Ver
    10
    Posts
    35

    Re: Macro that deletes empty columns but also removes leading zeros

    Ok, I have formatted the columns with zeros as "Text" and run the code and it works. Ok, there are a lot of columns that require formatting as "Text" so I ran a macro that basically formats certain columns as "Text" after copying and pasting the data in to the worksheet. I then run the macro as above and all columns disappear with the exception of A and B.

    Here is the copy, paste and format macro
    Please Login or Register  to view this content.
    Ok not pretty but it works. The data copies,pastes and formats. Now, when I run the other macro

    Please Login or Register  to view this content.
    the macro no longer works. Any thoughts? Could it be because I have formatted several columns (E,F, K,L, Q,R, W,X, AC,AD, AI,AJ, AO,AP, AU,AV, BA,BB, BG,BH, BM,BN, BS,BT, BY,BZ, CE,CF, CK,CL, CQ,CR, CW,CX, DC,DD, DI,DJ, DO,DP, DU,DV, EA,EB, EG,EH, EM,EN, ES, ET) as "Text" and they are causing the problem? I cannot see why this would be.

    Thoughts?

    Tony

    Since posting I have proved that the other "Text" formatted columns are indeed "blocking" the deletion of the empty columns. So I have to find a way of making the macro "ignore" empty "Text" formatted columns.
    Last edited by BigTP; 05-17-2018 at 07:32 AM. Reason: Further tests

  5. #5
    Registered User
    Join Date
    03-22-2018
    Location
    Taunton, England
    MS-Off Ver
    10
    Posts
    35

    Re: Macro that deletes empty columns but also removes leading zeros

    Hi there

    Any help on this out there?

    Tony

+ 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. Excel removes leading zeros
    By palapeli in forum Excel General
    Replies: 7
    Last Post: 03-26-2024, 12:57 AM
  2. [SOLVED] Text to columns VBA keep leading zeros
    By forrestgump1980 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-04-2017, 08:43 AM
  3. Macro that removes empty rows within a table
    By airedale360 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-10-2016, 07:24 PM
  4. Replies: 2
    Last Post: 02-07-2016, 03:28 PM
  5. Replies: 6
    Last Post: 01-11-2012, 01:48 PM
  6. split column into two columns and keep leading zeros
    By BuzzMicron in forum Excel General
    Replies: 5
    Last Post: 12-29-2011, 07:05 PM
  7. [SOLVED] TEXT TO COLUMNS WITH LEADING ZEROS
    By Peggy in forum Excel General
    Replies: 1
    Last Post: 06-16-2005, 09: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