Closed Thread
Results 1 to 19 of 19

Delete empty cells, and shift left

  1. #1
    Registered User
    Join Date
    09-28-2008
    Location
    UK
    MS-Off Ver
    MS 365 Apps for Enterprise
    Posts
    64

    Delete empty cells, and shift left

    Hi there,

    I am trying to find a method for deleting empty cells in a range and shift cells left upon deletion automatically. I could do this manually, but with 3000 rows of data it could be a long task. I have attched a small spreadsheet to show what I am looking for.

    I hope someone can help me! (again)
    Attached Files Attached Files
    Last edited by kiboodez; 10-07-2008 at 01:13 PM.

  2. #2
    Registered User
    Join Date
    10-07-2008
    Location
    Wessex
    Posts
    55
    Please Login or Register  to view this content.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    Even though this is in the Excel Functions area, the following VBA procedure is one way and maybe easier than a complex set of function/fomulae

    Name the cell at the top of your range ("Top"), i.e the Z cell in the example, and name a cell where you want the output to appear "Output"

    Now run the following procedure:

    Please Login or Register  to view this content.
    HTH

  4. #4
    Registered User
    Join Date
    09-28-2008
    Location
    UK
    MS-Off Ver
    MS 365 Apps for Enterprise
    Posts
    64

    Sorry for being me...

    I have pasted both of the above selections in as code, as I am not a VBA user I do not know how to get them to run, or how to change the data range they work with.

    Please help a useless man in distress!

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    You can name cells by going to the formula bar and with your cursor on the cell (or range) you want to name, just enter the name. In the case two names "Top" for cell B1, and "Output" for B10 in this example.

    Now hit the ALt-F11 Keys to take you into the VB Enviroment. In the Project - VBAProject window on the left, double click on the 'ThisWorkbook' item uder your workbook, and in the big code window that opens on the right, paste the code I gave you earlier.

    Now Al-F11 back to Excel

    In the Tools Macro Macros menu find the macro called 'ShiftValuesLeft' and run it.

    If you're going to use it frequently I suggest you add an object/picture/icon or something to the ws, and the right click and attach the macro to the object so that you can run it just by clicking the object.

    HTH

    HTH

    Regards

  6. #6
    Registered User
    Join Date
    09-28-2008
    Location
    UK
    MS-Off Ver
    MS 365 Apps for Enterprise
    Posts
    64

    Superb

    Thanks very much for the help. I love this forum, I learn more and more everyday!

  7. #7
    Registered User
    Join Date
    03-11-2011
    Location
    Stanford, California
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Delete empty cells, and shift left

    Hey Richard - just wanted to say thanks...you saved me oodles of time on a huge project : )!!

  8. #8
    Registered User
    Join Date
    04-25-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2003
    Posts
    1

    Red face Re: Delete empty cells, and shift left

    Richard,

    This vb macro works great... for up to 7 columns and up to 6500 rows...

    I am working with data that has 9 columns and 15000 rows. Is there something I'm missing? Is there an edit to this code that i can perform that would delete cells past column 7 and row 6501?

    Thanks,

    Paul

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Delete empty cells, and shift left

    Hi Paul,

    Apologies but I've only just seen this.

    The macro uses the .CurrentRegion property of the range and this will cover all contiguous rows & columns. The fact that you state it's not covering all your data suggests that you have a blank column after col 7 and a blank row after 6501.

    If you know the last row and column then you could simply set the iRows and iColumns variables to be whatever numbers you want, e.g 15000 & 9

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  10. #10
    Registered User
    Join Date
    01-13-2012
    Location
    Michigan/Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Delete empty cells, and shift left

    Sorry for resurrecting an old thread, but I am trying to accomplish the same thing as the OP. I have a spreadsheet with functions in each cell. Some cells have a blank result. I would like to delete the empty cells and shift everything left. Can I use vlookup? I'm not familiar with Visual Basic. Any advice would be appreciated.

  11. #11
    Registered User
    Join Date
    11-09-2012
    Location
    Oregon, USA
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Delete empty cells, and shift left

    WOW! Like mccarthyxa said, this code is awesome! Saved me so much time.

  12. #12
    Registered User
    Join Date
    09-28-2008
    Location
    UK
    MS-Off Ver
    MS 365 Apps for Enterprise
    Posts
    64

    Re: Delete empty cells, and shift left

    Hi guys,

    I posted the original question for this some time ago, and have been using the fantastic code ever since!

    I now have a small addendum though, any help would be appreciate.

    I am looking to achieve the same thing, but rather than deleting empty cells, deleting those with no colour - any suggestions appreciated.

  13. #13
    Registered User
    Join Date
    11-09-2012
    Location
    Oregon, USA
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Delete empty cells, and shift left

    Hello,

    I spoke too soon. The code is great but seems to have a limit. I have 85 columns and 48,000+ rows. When I run the macro, I get a "Run-time error '6': Overflow" message. Any ideas on how to fix this?

    Thanks!

  14. #14
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete empty cells, and shift left

    Msawyer,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  15. #15
    Registered User
    Join Date
    11-09-2012
    Location
    Oregon, USA
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Delete empty cells, and shift left

    Sorry about that. I will post a new thread.

  16. #16
    Registered User
    Join Date
    03-06-2013
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Delete empty cells, and shift left

    Thanks so much for this, I also needed it badly

  17. #17
    Registered User
    Join Date
    03-20-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Delete empty cells, and shift left

    What a wonderful little piece of code!!! So many keystrokes saved!!
    Many thanks to Mr. Buttrey!

  18. #18
    Registered User
    Join Date
    07-25-2014
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    5

    Re: Delete empty cells, and shift left

    HI, sorry for resurrecting an old thread but i've tried this macro and I get a message saying Microsoft Visual Basic - 400. I can't figured out what I've done wrong, any help would be much appreciated.

  19. #19
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Delete empty cells, and shift left

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Delete empty cells and shift remaining left
    By kiboodez in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2010, 02:17 PM
  2. Delete with shift causes cells loose fill & border around
    By mikeburg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2008, 03:40 AM
  3. Insert, shift cells down and populate
    By ugg in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-04-2007, 02:47 AM
  4. SHIFT + ENTER not working on some cells Excel 2003
    By debnla in forum Excel General
    Replies: 1
    Last Post: 07-17-2007, 09:27 PM
  5. Delete cell and shift cell up
    By mridzuan in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-23-2007, 12:20 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