+ Reply to Thread
Results 1 to 19 of 19

Msgbox all empty rows in a range

  1. #1
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Msgbox all empty rows in a range

    I have a range B18:B190 that can be populated from time to time either fully (ie all rows are used) or sometimes only B18:B100 for example are populated.
    This works great but on occasion I notice that there are a few blank rows thrown into my range by colleagues of mine who insert/delete rows (which I do want them to be allowed to do) but I would like to have a macro I can run that gives me a messagebox telling me which rows in my range have blank rows.
    I do not want the messagebox to tell me about the blank rows that exist after my last row of data though, as in the example above I dont want to know about rows 101-190 as they are meant to be blank...

    as a more thorough example, let me say that there were populated rows of B18:B50, row 51 was blank, B52:B100 were populated, row 101 was blank and B102:B150 were populated and then B151to B190 were blank (as they are supposed to be as that is the end of the data) I would want a messagebox to say
    "Blank rows in 51 and 101"

    any ideas?

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Msgbox all empty rows in a range

    Try:
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Msgbox all empty rows in a range

    Please Login or Register  to view this content.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  4. #4
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Msgbox all empty rows in a range

    Olly - that works great, but only if there are blank rows to find. - how do you change it so that it doesnt crash if there are NO blank cells?

    Nathansav - I get a syntax error on the line
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Msgbox all empty rows in a range

    add a space between s and &

  6. #6
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Msgbox all empty rows in a range

    nathansav,
    ah thats better. However it still returns all the blanks from the last used row in my range to 191 which I dont want as they are supposed to be blank in that case.

    EDIT: fixed that with
    Please Login or Register  to view this content.

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Msgbox all empty rows in a range

    Quote Originally Posted by nickmax1 View Post
    Olly - that works great, but only if there are blank rows to find. - how do you change it so that it doesnt crash if there are NO blank cells?
    Adding a bit of error handling:
    Please Login or Register  to view this content.
    Also tweaked to return just the rows, not the full cell addresses.

  8. #8
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Msgbox all empty rows in a range

    both Olly and Nathansav's code works but only when my range is entirely unhidden (or unfiltered) ?

  9. #9
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Msgbox all empty rows in a range

    My code in post #7 seems to work fine for me, regardless of hidden / filtered rows.

    Can you attach a workbook demonstrating what's not working right?

  10. #10
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Msgbox all empty rows in a range

    OK.
    See attached. As it is your macro will run nicely and identify row 141 as being blank. But if you hide say rows 138-150 and run the macro it wont find it...
    Attached Files Attached Files

  11. #11
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Msgbox all empty rows in a range

    I see now. The end(xlup) skips past the hidden rows at the bottom of your used range. So we need to find the last used cell in column B a slightly different way:

    Please Login or Register  to view this content.
    Better?

  12. #12
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Msgbox all empty rows in a range

    Olly
    Fantastic that solves that problem, but now the macro identifies the empty cells between the last used row of the specified range to 191 as well which we dont want.

  13. #13
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Msgbox all empty rows in a range

    It doesn't do that for me...

    In the file you attached in post #10, I run the following code:
    Please Login or Register  to view this content.
    And it returns the following msgbox:

    "Blank cells in 141"


  14. #14
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Msgbox all empty rows in a range

    driving me nuts, it works fine on the test one but not on the master....so here it is...why doesnt it work here?

    i am expecting it to return "row 164 and 165 are blank" or similar.
    Attached Files Attached Files

  15. #15
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Msgbox all empty rows in a range

    Ah - different corresponding data in column A!

    Change this line:
    Please Login or Register  to view this content.
    to this:
    Please Login or Register  to view this content.

  16. #16
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Msgbox all empty rows in a range

    works !! yes!!

    One final - once it has determined the rows, any way you can add code to clear the contents of said rows?
    Last edited by nickmax1; 09-11-2014 at 11:22 AM.

  17. #17
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Msgbox all empty rows in a range

    may have figured it out with:

    Please Login or Register  to view this content.

  18. #18
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Msgbox all empty rows in a range

    Yes, that would do. It's one of the reasons why the range object 'r' was created, to make it easier to do something with, as well as just the message box.

  19. #19
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Msgbox all empty rows in a range

    you are a star. rep added. thread solved.

+ 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. Need help deleting empty rows from a range from the bottom of the list up
    By pasqualebaldi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2014, 07:48 PM
  2. Display msgbox if two cells in range are not empty
    By loroverde in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2014, 12:49 AM
  3. [SOLVED] Delete empty rows in range after last used row
    By crakter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-26-2013, 12:30 PM
  4. Msgbox - when cell is empty
    By KA_Analyst in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-15-2007, 04:36 PM
  5. [SOLVED] empty rows in range
    By רוזנט in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-05-2006, 05:10 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