+ Reply to Thread
Results 1 to 8 of 8

Automatically delete rows where last column has blank data

  1. #1
    Registered User
    Join Date
    07-24-2019
    Location
    Houston
    MS-Off Ver
    2019 Standard
    Posts
    10

    Automatically delete rows where last column has blank data

    Hi, I have Excel 2019 and constantly have to download data from a program. The last column has some rows with blanks, and I want to be able to delete those rows without having to filter to blanks, select the rows, and delete them (constantly!).

    I have attached an example.

    The column where I need to filter to blanks is always named the same thing, and it is always the last column, but the number of columns can vary.

    Does anyone have a macro that will do this?

    Thank you in advance!
    Attached Files Attached Files
    Last edited by Sandi770; 03-31-2023 at 12:27 PM. Reason: spelling

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Automatically delete rows where last column has blank data


    Hi,

    as a VBA procedure can reproduce what is achieved manually so why not filtering / deleting ?!
    Easy to start with the Macro Recorder …

    Another way than an Excel filter is to use the tricky SpecialCells statement as explained in VBA help …

  3. #3
    Registered User
    Join Date
    07-24-2019
    Location
    Houston
    MS-Off Ver
    2019 Standard
    Posts
    10

    Re: Automatically delete rows where last column has blank data

    Thank you, how does the Macro Recorder know to filter by that specific column? It's not always the same number of columns in the sheet. I don't write VBA (novice) so I'm not sure what you mean by SpecialCells.
    Last edited by Sandi770; 03-31-2023 at 12:26 PM.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Automatically delete rows where last column has blank data


    As I just mean what is explained in VBA help …

    The Macro Recorder as per its name and its purpose just records your actions to some VBA procedure.
    So once that works manually, activate it, redo the same operations in order to get a code base …
    From this base you will post here - with the codes tags (via # icon) as per this forum rules - I will revamp it
    in order to work whatever the last column is, such a good start for you to learn !

  5. #5
    Registered User
    Join Date
    07-24-2019
    Location
    Houston
    MS-Off Ver
    2019 Standard
    Posts
    10

    Re: Automatically delete rows where last column has blank data

    Here is the Macro that I recorded:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Re: Automatically delete rows where last column has blank data


    This recorded procedure must be not launched if there is no blank cell within the last column or SpecialCells will crash it
    like you can check just running it twice and, as Delete works already only with visible cells, so it is useless here !

    Let's see first the filter method so like whatever could be the criteria but first two points :
    UsedRange is usefull with a smart designed worksheet.
    According to your attachment with the useless comments column that's no more the case
    so first insert a blank column between columns J & K in order this comments column moves to column L
    so in this case the CurrentRegion can be exploited rather than UsedRange :
    Please Login or Register  to view this content.

    According to the VBA help let's see now the direct SpecialCells way but not for the visible but for the blank cells.
    As this tricky method crashes when nothing matches so before to use it the VBA procedure must first check
    if only a blank cell exists via the worksheet function COUNTBLANK :
    Please Login or Register  to view this content.
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 03-31-2023 at 03:52 PM.

  7. #7
    Registered User
    Join Date
    07-24-2019
    Location
    Houston
    MS-Off Ver
    2019 Standard
    Posts
    10

    Re: Automatically delete rows where last column has blank data

    OMG It's a miracle - just awesome!

    Thank you so very very much!

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Automatically delete rows where last column has blank data


    Thanks for the rep' !

    LoL ! Not a miracle as all is yet explained in both Excel & VBA helps, as knowledge is first reading …

+ 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] Delete blank rows between blocks of data except two blank rows
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-26-2018, 11:18 AM
  2. VBA, Delete blank rows with no visible data in Column A
    By TylerLuk1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-20-2015, 10:06 AM
  3. Delete Blank Column Automatically
    By keen2xl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-12-2013, 12:03 AM
  4. Macro to delete blank rows if column I is blank for the row
    By tiger10012 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-10-2013, 03:01 PM
  5. Replies: 3
    Last Post: 07-17-2013, 01:25 AM
  6. [SOLVED] VBA Find last row and column that contain data and delete all blank rows and blank columns
    By bcn1988 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-03-2012, 01:07 PM
  7. Replies: 1
    Last Post: 05-10-2012, 04:58 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