+ Reply to Thread
Results 1 to 12 of 12

Delete all blank records within data set

  1. #1
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Delete all blank records within data set

    Hello!

    I have a table that can have up to 65000 records in it. The issue I have is there are a ton of BLANK records. What I want is to have some code that will delete ALL the blank records within the data set. The number of columns is from A:AM . Please let me know if you have any questions or need any additional information.

    Thanks!

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Delete all blank records within data set

    So if there is a blank, would you want to delete the whole row??
    Cheers!
    Deep Dave

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Delete all blank records within data set

    It isn't clear how these blank records are located and in which way you want to delete them. Example1: The blank cells could be in any column and any row; or the blank cells are only in column E but could be located in any row. Example2: I need to delete the entire row if one cell is blank; or I only need to delete the cell and shift everything else up if it is empty.

    Please specify what your requirements are.

  4. #4
    Registered User
    Join Date
    01-28-2013
    Location
    Coventry
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Delete all blank records within data set

    try this


    Please Login or Register  to view this content.
    DESCRIPTION
    If cells in first column (Cells(a,1)) is empty then delete row. If you want to look at second col, change the code from Cells(a,1) to Cells(a,2). Likewise, if you want first col and second col, IsEmpty(Cells(A, 1)) And IsEmpty(Cells(A, 2))
    It defines var as used rows in spreadsheet, and updates var everytime it does a loop.

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Delete all blank records within data set

    Macros are not required.

    Filter you table on the key column(s) for blanks, > delete the resulting blank rows > Remove the filter.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  6. #6
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Delete all blank records within data set

    Hey a8015945,


    That almost worked. I think the code deleted a record even if there was one cell in the record that was blank. So hopefully this will clarify for you as well as everyone else that had replied to the post.
    1) The data set contains columns A through AM. If one of the columns within the record, let's say B10 (row 10) is blank, I do NOT want this record deleted. I ONLY want the the ENTIRE ROW to be deleted if each cell within the row is blank. So if A10 through AM10 (each cell is blank) then delete row 10.
    2) I do not want to have to do any manual work (i.e. filters)

    Thank you for all your help! Please let me know if there are any other questions that i can answer.

  7. #7
    Registered User
    Join Date
    01-28-2013
    Location
    Coventry
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Delete all blank records within data set

    Ok let me have another look at the loop.

  8. #8
    Registered User
    Join Date
    01-28-2013
    Location
    Coventry
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Delete all blank records within data set

    try this one now then

    Please Login or Register  to view this content.
    DESCRIPTION.
    Slight change from previous code. Now the macro looks at each cell in the row. If the cell is NOT empty (e.g. has a value) then the macro looks at the next row. For each EMPTY cell in the row, x is incremented. If x=total number of columns, then the row must be EMPTY, therefore Rows(r).Delete

    NOTE 1
    Macros dont update themselves, they have to be started manually. You can do this by adding an autoshape, then right click and ASSIGN MACRO.

    NOTE 2
    Deleting rows in this fashion may take some time, depending on number of empty rows, total number of rows etc. You may need to allow anywhere upto 5 minutes depending on the situation.

  9. #9
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Delete all blank records within data set

    This Loop should be faster
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    01-28-2013
    Location
    Coventry
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Delete all blank records within data set

    Marcol I have spotted a mistake in your code.

    ORIGINAL
    If WorksheetFunction.CountA(Range("A" & RowNo & ":AM" & RowNo)) = 0 Then Cells(1, RowNo).EntireRow.Delete

    UPDATED
    If WorksheetFunction.CountA(Range("A" & RowNo & ":AM" & RowNo)) = 0 Then Cells(RowNo,1).EntireRow.Delete

    When I tired your original on a dummy spreadsheet, it deleted the majority of the data, when I made the change it did exactly what it should do.

    P.S. By the way, thanks for sharing this method of coding. As you can probably guess, i'm reletavely new to programming macros (self taught over 4 months) so I often aim for something that just gets results, rather than aiming for effieciency atm. And to top things off, my dad is from Fife, small world

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

    Re: Delete all blank records within data set

    hmm...

    whatever happened to the filter?

    here's another to try. should work fine with 65,000 rows
    Please Login or Register  to view this content.

  12. #12
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Delete all blank records within data set

    Quote Originally Posted by a8015945 View Post
    Marcol I have spotted a mistake in your code.
    Well spotted your suggestion is correct, lazyness on my behalf ...

    whatever happened to the filter?
    If you want to try using Autofilter this might be easier
    Please Login or Register  to view this content.

+ 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