+ Reply to Thread
Results 1 to 20 of 20

Empty cells not evaluating as empty - multiple check methods tried

  1. #1
    Registered User
    Join Date
    01-31-2014
    Location
    Milwaukee
    MS-Off Ver
    Excel 2010
    Posts
    16

    Empty cells not evaluating as empty - multiple check methods tried

    I have an inelegant global macro that I'm trying to refine. Here's the old one:

    Please Login or Register  to view this content.
    This all works nicely, except I'm limited to six rows. I'd like to iterate a loop to unlimit myself, because I suspect I'll be getting bigger sheets with more blanks needing to be checked.

    Here's what I've come up with:

    Please Login or Register  to view this content.
    Line 04 is failing to evaluate properly. I have tried the following:

    stuff = ""
    stuff = vbNullString
    IsEmpty(stuff)
    IsEmpty(Range(stuff))
    IsEmpty(Range("stuff"))
    IsEmpty(Cells(stuff))
    IsEmpty(Cells("stuff"))

    I've also tried all those variants with stuff.Value.

    Stepping through this new macro with nested For loops, it will arrive at line 04, then jump down to line 08. This happens on every single row, regardless of the state of .Offset(1,1), regardless of what method I use to check if it's empty.

    What I don't understand is why in the old macro, = "" works, with nothing working when checking the same row on the same sheet with the new one.

    What am I missing?

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Empty cells not evaluating as empty - multiple check methods tried

    does this need to be

    old
    Please Login or Register  to view this content.
    new
    Please Login or Register  to view this content.
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Registered User
    Join Date
    01-31-2014
    Location
    Milwaukee
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Empty cells not evaluating as empty - multiple check methods tried

    Quote Originally Posted by judgeh59 View Post
    does this need to be

    old
    Please Login or Register  to view this content.
    new
    Please Login or Register  to view this content.
    I don't get what you're asking. I've tried that variation, and it still doesn't evaluate TRUE.

  4. #4
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Empty cells not evaluating as empty - multiple check methods tried

    gotcha - I didn't see that in the list of things you have tried....

    maybe try

    Please Login or Register  to view this content.
    if that doesn't work....on the cell you are evaluating, not using VBA, click on a blank cell and type

    =LEN(<cell reference)
    it should come back as 0

  5. #5
    Registered User
    Join Date
    01-31-2014
    Location
    Milwaukee
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Empty cells not evaluating as empty - multiple check methods tried

    Quote Originally Posted by judgeh59 View Post
    gotcha - I didn't see that in the list of things you have tried....

    maybe try

    Please Login or Register  to view this content.
    if that doesn't work....on the cell you are evaluating, not using VBA, click on a blank cell and type

    =LEN(<cell reference)
    it should come back as 0
    Tried TRIM(), still failing. LEN() on the cell in question returns 0.

  6. #6
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Empty cells not evaluating as empty - multiple check methods tried

    is it possible to upload a small sample file after taking out any company confidential stuff and with the macro?

  7. #7
    Registered User
    Join Date
    01-31-2014
    Location
    Milwaukee
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Empty cells not evaluating as empty - multiple check methods tried

    Sure. Where? I don't see an attachment function here.

  8. #8
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Empty cells not evaluating as empty - multiple check methods tried

    check the FAQ section....but basically instead of clicking POST QUICK REPLY, click GO ADVANCED and there is an add attachment area.....yup, not very inituitive....

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Empty cells not evaluating as empty - multiple check methods tried

    What is your code meant to do?

    Why do you have 2 identical loops in it?

    PS To attach - Click Go Advanced, then click the paperclip, just like you would if attaching a file to an email.
    If posting code please use code tags, see here.

  10. #10
    Registered User
    Join Date
    01-31-2014
    Location
    Milwaukee
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Empty cells not evaluating as empty - multiple check methods tried

    bb0102 - Copy.xlsx

    Old macro:

    Please Login or Register  to view this content.
    New macro:

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    01-31-2014
    Location
    Milwaukee
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Empty cells not evaluating as empty - multiple check methods tried

    If you look at rows 203-209 as an example, you'll see what I'm trying to accomplish: Sum O203:O209 (that's the total on order), add to H203 (that's the on-hand quantity), compare to G203 (that's allocations for that part), write I203 or zero in E203 depending on that comparison.

    First macro works flawlessly. Second one fails to evaluate F204 as empty - why?

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Empty cells not evaluating as empty - multiple check methods tried

    Does the code ever reach F204?

  13. #13
    Registered User
    Join Date
    01-31-2014
    Location
    Milwaukee
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Empty cells not evaluating as empty - multiple check methods tried

    That's the cell being evaluated with .Offset(1, 1). The macro steps to the If, then jumps to the Else. I don't know a better answer to your question, sorry.

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Empty cells not evaluating as empty - multiple check methods tried

    I've checked and the inner loop doesn't go beyond E2,

    You can see that if you put a debug line in the code like this.
    Please Login or Register  to view this content.

    If you look at the Immediate Window (CTRL+G) after you've run the code you'll hopefully see what I mean.

  15. #15
    Registered User
    Join Date
    01-31-2014
    Location
    Milwaukee
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Empty cells not evaluating as empty - multiple check methods tried

    Quote Originally Posted by Norie View Post
    I've checked and the inner loop doesn't go beyond E2,

    You can see that if you put a debug line in the code like this.
    Please Login or Register  to view this content.

    If you look at the Immediate Window (CTRL+G) after you've run the code you'll hopefully see what I mean.
    OK, I see that now. What do I do with this information? I don't know how to change my code accordingly; nothing is jumping out at me as causing this behavior.

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Empty cells not evaluating as empty - multiple check methods tried

    Rows is 0 at the start.

    E2 is the first cell in the inner loop and E2.Offset(1, 1) <>"" so the code skips to here,
    Please Login or Register  to view this content.
    then to here.
    Please Login or Register  to view this content.
    The code then goes back to here starting at E2 again,
    Please Login or Register  to view this content.
    and the same thing happens again until all the iterations of the outer loop are completed.

  17. #17
    Registered User
    Join Date
    01-31-2014
    Location
    Milwaukee
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Empty cells not evaluating as empty - multiple check methods tried

    Quote Originally Posted by Norie View Post
    Rows is 0 at the start.

    E2 is the first cell in the inner loop and E2.Offset(1, 1) <>"" so the code skips to here,
    Please Login or Register  to view this content.
    then to here.
    Please Login or Register  to view this content.
    The code then goes back to here starting at E2 again,
    Please Login or Register  to view this content.
    and the same thing happens again until all the iterations of the outer loop are completed.
    Ohhhhhhhhh.

    Alright.

    What I need to happen is for the inner loop to start iterating on the same row that the outer loop is on when the inner loop is called. How do I manage that?

    I can create a variable called MyRow, and set it in the outer loop with MyRow = ActiveCell.Row, but I don't know how, in the inner loop, to set the Active Row via a variable's value. If I could do that, it'd solve my problem, yes?

    Edit -

    Is the answer right here?
    Please Login or Register  to view this content.
    Replace the 2 with "ActiveCell.Row" or something like that?
    Last edited by rafadavidc; 02-03-2014 at 03:37 PM.

  18. #18
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Empty cells not evaluating as empty - multiple check methods tried

    You wouldn't use ActiveCell, you would use the loop variable from the outer loop - curCell.

    Something like this.
    Please Login or Register  to view this content.
    However I'm not sure that will fix the problem.

  19. #19
    Registered User
    Join Date
    01-31-2014
    Location
    Milwaukee
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Empty cells not evaluating as empty - multiple check methods tried

    Quote Originally Posted by Norie View Post
    You wouldn't use ActiveCell, you would use the loop variable from the outer loop - curCell.

    Something like this.
    Please Login or Register  to view this content.
    However I'm not sure that will fix the problem.
    I don't understand Range calls that well. Can you English out your code suggestion for me?

    That is to say, Why call the variable first, then the Range? That's not how the Range call works in the outer loop. What's the syntax rule you're following that requires you to do [variable]-comma-space-Range("[partial Range]" and the rest as I would expect)?
    Last edited by rafadavidc; 02-03-2014 at 05:24 PM.

  20. #20
    Registered User
    Join Date
    01-31-2014
    Location
    Milwaukee
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Empty cells not evaluating as empty - multiple check methods tried

    Tried it. Ending up with somewhat the opposite problem - Now, I'm failing to get quantities in multi-row parts where I should, instead of getting quantities where I shouldn't.

    Ctrl+G shows that the inner loop only operated on rows 583 to 685. Not sure why that should be.

  21. #21
    Registered User
    Join Date
    01-31-2014
    Location
    Milwaukee
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Empty cells not evaluating as empty - multiple check methods tried

    This helped. It also helped me understand just WHY I'm concatenating LastRow into my Range.

    Here's my rowsCell Range:

    Please Login or Register  to view this content.
    Result is.....

    Fail.

    Rows 66 and 67 should result in E66 being populated. Instead, I get a zero there. Buh.

    EDIT

    Range issue is solved. With this out of the way, I've watched the loop as it steps through iterations of the inner loop and seen it flail without a way to break out at the appropriate time. Thanks for your help on this; I now know what's wrong, and it's just a matter of basic programming principles at this point.
    Last edited by rafadavidc; 02-03-2014 at 06:05 PM.

+ 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. Check for multiple range and if any cell is not empty do something
    By tohor in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-31-2017, 12:24 PM
  2. Need help evaluating two pairs or four cells for empty values
    By guy69 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-20-2012, 11:33 AM
  3. check if multiple text boxes are empty
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-17-2009, 09:37 PM
  4. check for non-empty cells outside of a certain range
    By Abe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-28-2006, 01:50 PM
  5. Evaluating a Range of Empty Cells with VBA
    By John Mansfield in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-24-2005, 05:06 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