+ Reply to Thread
Results 1 to 9 of 9

Macro to delete blank rows if column I is blank for the row

  1. #1
    Registered User
    Join Date
    06-17-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    52

    Macro to delete blank rows if column I is blank for the row

    Hello all,
    I am looking for a macro to delete blank rows.

    The catch....I only care if column I is blank for the row. There could be data in any other columns for that row, but I still want to delete the row (e.g. if I20 is blank, delete the 20 row regardless if A20 has info, B20 has info, etc).

    Thank you to all for looking at my issue!

  2. #2
    Registered User
    Join Date
    02-11-2009
    Location
    boston
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Macro to delete blank rows if column I is blank for the row

    I'm running into the same issue as you are. I've come up with this in VBA, but it only partially works

    Please Login or Register  to view this content.
    the problem with this is that a) you have to define the range (in this case I defined it to only look at 50 rows) and b) if row 28 and 29 are blank, it will only delete row 28. Once it deletes row 28, row 29 now becomes row 28, but since the code already deleted row 28, it jumps to the "new" row 29

    thoughts? (not trying to hijack your thread either - just running into similar issues)
    Last edited by jrs130; 09-10-2013 at 12:27 PM.

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,778

    Re: Macro to delete blank rows if column I is blank for the row

    Not knowing how your data is organized perhaps this will work?

    Please Login or Register  to view this content.
    Change ("Sheet1") part of macro to match name of your data sheet.

    Alf

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,778

    Re: Macro to delete blank rows if column I is blank for the row

    thoughts? (not trying to hijack your thread either - just running into similar issues)
    Try working from the bottom to the top instead i.e.

    Please Login or Register  to view this content.
    Alf
    Last edited by Alf; 09-10-2013 at 12:38 PM. Reason: Dimed i as Integer

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro to delete blank rows if column I is blank for the row

    Hi, tiger10012,

    the Autofilter will work fine for Formulas in Column I, if there are really only blanks (not formulas returning ""):
    Please Login or Register  to view this content.
    @Alf:
    I must admit I didnīt test your first code but might ActiveSheet.UsedRange.EntireRow.Delete interfere with the headers (delete these rows as well)?

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,778

    Re: Macro to delete blank rows if column I is blank for the row

    I must admit I didnīt test your first code but might ActiveSheet.UsedRange.EntireRow.Delete interfere with the headers (delete these rows as well)?
    Yes Holger it will and the solution to that is changing the "delete" line to

    Please Login or Register  to view this content.
    But then again as I said in my first post

    Not knowing how your data is organized perhaps this will work?
    so my solution is based on a guessimate.

    Alf

  7. #7
    Registered User
    Join Date
    02-11-2009
    Location
    boston
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Macro to delete blank rows if column I is blank for the row

    Quote Originally Posted by Alf View Post
    Try working from the bottom to the top instead i.e.

    Please Login or Register  to view this content.
    Alf
    Thanks Alf

    I tried the code but I'm getting a compile error: Next without for


    figured it out....needed and "End if" thx!
    Last edited by jrs130; 09-10-2013 at 12:52 PM.

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro to delete blank rows if column I is blank for the row

    Hi, Alf,

    and my code starts in Row 1 and maybe needs to be set to Row 3 to keep the additional rows over the headers as well as it refers to Column I for the last row which may not have data throughout and the letter for the column maybe needs to be changed to a Column with continuous data (maybe A). A deep look into a crystal ball for me as well.

    Please Login or Register  to view this content.
    Ciao,
    Holger
    Last edited by HaHoBe; 09-10-2013 at 12:54 PM.

  9. #9
    Registered User
    Join Date
    06-17-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Macro to delete blank rows if column I is blank for the row

    Thank you very much Alf and HaHoBe for the replies!

    HaHoBe....I tried the code but kept getting an issue. Everytime I ran the macro, a new module was created with "Sub EF953950()" and "End Sub" populated. I understood what you were saying and was able to get it working perfectly with slight modifications....

    Please Login or Register  to view this content.
    Alf, I was a little fearful of using the filter option for the current data I have, as I have seen entire columns blank in the middle of the data I received. I was greatful to see how filters work in VBA and will most likely use your code in another spreadsheet I have.

    Thank you both!

  10. #10
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,778

    Re: Macro to delete blank rows if column I is blank for the row

    Hi

    Thanks for feedback and rep. You could "compress" the code a bit more if you wish i.e.

    Please Login or Register  to view this content.
    should work just as well. For headings as Holger pointed out you add the Offset command. So an offset of 3 will "save" the 3 top rows in the filtered range i.e.

    Please Login or Register  to view this content.
    The Offset command has a row and a column offset. If only one number is given it is interpreted as a row offset. For a column offset the command could be

    Please Login or Register  to view this content.
    This will copy the used range ignoring the first two columns with data.

    An alternative to using "ActiveSheet.UsedRange" is the "CurrentRegion" command. Very handy when working with tables or you has data surrounded by text that should not be included but your data must be “isolated” by a blank range all around it.

    In this case you need to add the upper left corner of your data range i.e.

    Please Login or Register  to view this content.
    Alf

+ 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] 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
  2. [SOLVED] How to Delete Multiple Consecutive Blank Rows - Delete all Blank Rows
    By raw_geek in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 11-16-2012, 03:17 PM
  3. Replies: 1
    Last Post: 05-10-2012, 04:58 PM
  4. [SOLVED] To delete blank rows having blank cell in the needed raws
    By Alexander_Golinsky in forum Excel General
    Replies: 4
    Last Post: 05-04-2012, 03:11 PM
  5. Delete Blank Rows-Blank Row between my data range
    By Bob@Sun in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-27-2010, 02:52 PM

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