+ Reply to Thread
Results 1 to 7 of 7

Delete cells if blank, shift left until data found

  1. #1
    Registered User
    Join Date
    04-25-2013
    Location
    perth, australia
    MS-Off Ver
    Excel 2011
    Posts
    22

    Delete cells if blank, shift left until data found

    Hi guys,

    I have a large dataset (4000 rows) that I have imported from the web, but unfortunately it has inserted blank cells in front of my data such the last row has data beginning in column A, the second last in column D, the third last in column G, etc. So in each ascending row the data begins three columns further to the left than the data in the row below it. This is super annoying.

    I would simply like a macro that begins in cell A1, deletes the cell if it is blank, then moves to cell A2 (which would now be A1), deletes it if blank, cell A3, etc until it finds a non-blank cell, then it moves to A2 and loops through all the rows until it finds no more data. An additional complication: Some of the rows are empty and these can be ignored by the macro. When the cells are deleted, the cells obviously need to be shifted left.

    Any help would be greatly appreciated.
    example.xlsx

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Delete cells if blank, shift left until data found

    Try this,

    Please Login or Register  to view this content.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Registered User
    Join Date
    04-25-2013
    Location
    perth, australia
    MS-Off Ver
    Excel 2011
    Posts
    22

    Re: Delete cells if blank, shift left until data found

    Hi Dave,

    Thanks that worked pretty well. One tiny problem which I didn't foresee. Occasionally my data contains blank cells in the data. (e.g. AA, AA, AA, blank, AA). I want these to be retained. So if the row looked like:
    blank, blank, blank, AA, AA, AA, blank, AA
    I would want the macro to delete the first three blank cells, but cease once it finds non-blank cells, such that it returns, AA, AA, AA, blank, AA

    I'm sure this is possible, but I'm a bit of a rookie here.

    Thanks again.

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Delete cells if blank, shift left until data found

    So , only the blank cells to the left,

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-25-2013
    Location
    perth, australia
    MS-Off Ver
    Excel 2011
    Posts
    22

    Re: Delete cells if blank, shift left until data found

    I get Runtime Error '13': Type mismatch

    And I'm not sure why. Sorry to be a pain

  6. #6
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Delete cells if blank, shift left until data found

    It works on your sample file.

    Where are you getting the error?
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Delete cells if blank, shift left until data found

    I think error 13 might happen if column1 is entirely empty

    probably easily fixed, but as alternative you might like to try
    Please Login or Register  to view this content.
    Last edited by kalak; 07-04-2013 at 07:14 AM.

  8. #8
    Registered User
    Join Date
    04-25-2013
    Location
    perth, australia
    MS-Off Ver
    Excel 2011
    Posts
    22

    Re: Delete cells if blank, shift left until data found

    Thanks guys, I'm away on holiday for five days now without access to my files. I'll have a look again when i get back. Thanks for all the help.

+ 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