+ Reply to Thread
Results 1 to 17 of 17

Use if then statement when cell or row is empty

  1. #1
    Registered User
    Join Date
    07-27-2013
    Location
    Roanoke
    MS-Off Ver
    Excel 2010
    Posts
    23

    Use if then statement when cell or row is empty

    I thought I was finished with my project but ran into a snag when the data is missing. I have several scripts that run as macros in an excel spreadsheet. They are done in steps. Step 1 I take a bunch of .dat files in the same folder and create .xlsx files with the text to columns to separate the data into columns. I also add a couple of blank worksheets to each of the newly created excel workbooks. The .dat files contain about 7,000 rows of data and I only need 1 row that matches my criteria. Step 2, I extract the data that matches my criteria and put them in the new worksheets. I couldn't figure out how to do the search/extract with 2 values....so I search using 1 value and put in the first new worksheet, then I search that new worksheet and extract the one row using the last criteria/value. I may post that code to see if anyone can help me fine tune that. Anyway, in Step 3, the final step, I copy the row of data from the worksheets and insert into a new workbook. All of this works fine, except on occasion there will be no data. The monitor may be offline or whatever the reason, there will be no data for that time period.

    Here's what the info will look like during my current runs. You will notice that there is no data and no row listed for 6:00

    Example_1.png

    I would like to insert an If Else statement so that if there is an empty row of data in the source worksheet then the text "missing data" will be inserted into the copy worksheet. So that the final workbook/worksheet will look like this.

    Example_2.png


    Here's my code. Note. I do try stuff I find on the internet and in this forum to try to help me solve my issue before I post my request for help. The people in this forum have been very helpful in getting me to my near completion of this project - it's for a non-profit, so your assistance is much appreciated. Thanks!

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Use if then statement when cell or row is empty

    Here's a snippet I usually use in these cases. Paste it into a standard module and 'Call' it from within your macro and to do so add this line where you correctly supposed your statement should go (or so it seems to me too):
    Please Login or Register  to view this content.
    Here is the snippet; adapt ranges if needed.
    Please Login or Register  to view this content.
    Last edited by rollis13; 02-21-2024 at 06:24 PM.
    Difficult is not to know but to share what you know (Han Fei Tzu reworked)

  3. #3
    Registered User
    Join Date
    07-27-2013
    Location
    Roanoke
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Use if then statement when cell or row is empty

    I'm not having any luck with the Call script. It stops at the first spreadsheet. I'll tinker with it some more. I appreciate your assistance. I don't need it to add or subtract the time. I just need that row to say "missing data" in cell A. That time column will actually get replaced later on with the correct time as this data is in GMT. So, I will have the offset time in another column. Thanks

  4. #4
    Registered User
    Join Date
    07-27-2013
    Location
    Roanoke
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Use if then statement when cell or row is empty

    Rollis13,

    That worked! Thanks so much. I just had to think about it a bit. In your script, I did change the data start row to 2, for some reason it starts on row 2.

    In my script I put the call function near the end, after the loop function. I had tried inserting it earlier and was running into issues.

    Please Login or Register  to view this content.

    Here's a screenshot of the finished excel. Thank you so much!


    Example_3.png

  5. #5
    Registered User
    Join Date
    07-27-2013
    Location
    Roanoke
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Use if then statement when cell or row is empty

    Oops. I discovered an issue when you look at multiple days. The call script wants to insert missing data between the hours of 2300 and 0000 when there is no missing data.

    Example_4.png

  6. #6
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Use if then statement when cell or row is empty

    Sorry, can't replicate your issue with my snippet (and my test data).

    Anyway, try changing this line to (> instead of <>):
    Please Login or Register  to view this content.
    Last edited by rollis13; 02-22-2024 at 07:41 AM.

  7. #7
    Registered User
    Join Date
    07-27-2013
    Location
    Roanoke
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Use if then statement when cell or row is empty

    That got it rollis13! I will test it some more but that seems to work perfectly. Thanks so much.

    Example_5.png
    Last edited by ecorf; 02-22-2024 at 10:10 AM.

  8. #8
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Use if then statement when cell or row is empty

    You may also need to add this other line; it will format as time a missing 0:00 (midnight), here:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-27-2013
    Location
    Roanoke
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Use if then statement when cell or row is empty

    Thanks for all your help. rollis 13! I'll do some additional testing in various scenarios to see if all is well.

    Just to keep it all straight. Here's the call subroutine as I currently have. I removed the Private just because it made it easier for me to edit during this testing period.

    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Use if then statement when cell or row is empty

    You are welcome; thanks for the feedback.

  11. #11
    Registered User
    Join Date
    07-27-2013
    Location
    Roanoke
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Use if then statement when cell or row is empty

    So close, but I did some additional testing and found that there are issues if the missing data is at 00:00 or at 23:00. It skips over those.

    Example_6.png

  12. #12
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Use if then statement when cell or row is empty

    As I said, I can't replicate the issue; please attach a sample of your data.

  13. #13
    Registered User
    Join Date
    07-27-2013
    Location
    Roanoke
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Use if then statement when cell or row is empty

    I tried adding 2 additional ElseIf statements but said it needed to be an array

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    07-27-2013
    Location
    Roanoke
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Use if then statement when cell or row is empty

    Here is a test spreadsheet with data. You will notice by the times that there are several lines of missing data. This is before our attempts to insert a row mentioning the "missing data".

    I should add that this spreadsheet is created by taking sheet 3 from separate spreadsheets for every hour listed. So, Before this test spreadsheet result, there are several spreadsheets of data....this final spreadsheet combines the one row that is in sheet 3 of all those spreadsheets. Thus, in those missing data times, sheet 3 would be blank as there would be no data. I mention this...as that may be an option to insert a row of info. Then, when I would create this final spreadsheet with all the data, that missing data issue would have already been addressed.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    07-27-2013
    Location
    Roanoke
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Use if then statement when cell or row is empty

    Here's my latest attempt of fixing the missing data if that missing data happens at 0:00 or 23:00. This does not throw any errors. It still works for the missing data if not at 0:00 or 23:00. However, it does nothing....does not add the missing data row for missing data at 0:00 or 23:00. Maybe I am misunderstanding the x - and x + functions. I will experiment with that a little.

    Please Login or Register  to view this content.

  16. #16
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,223

    Re: Use if then statement when cell or row is empty

    Customize the code below to suit your needs
    Please Login or Register  to view this content.
    Artik

  17. #17
    Registered User
    Join Date
    07-27-2013
    Location
    Roanoke
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Use if then statement when cell or row is empty

    Wow! That worked!

    Both Artik and Rollis13 rule! Now, I need to go line by line of what Artik provided and see if I can make some sense out of why it works. LOL!

    Thank you both!

    I should be able to leave you alone for awhile, I hope. Anyway, I very much appreciate your time and assistance.

+ 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] Using If cell not empty as criteria within a SUMIFS statement
    By pptdgc1999 in forum Excel Formulas & Functions
    Replies: 23
    Last Post: 04-30-2021, 04:57 PM
  2. IF statement help. If Adjacent cell is empty then..
    By wizzle89 in forum Excel General
    Replies: 6
    Last Post: 06-15-2015, 02:43 PM
  3. If statement Don't Show Data if cell is empty
    By PacE in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-04-2008, 04:57 PM
  4. if statement where cell is not empty
    By guerilla in forum Excel General
    Replies: 2
    Last Post: 10-01-2006, 08:41 PM
  5. if statement for empty cell
    By CORY in forum Excel General
    Replies: 1
    Last Post: 02-03-2006, 02:30 PM
  6. [SOLVED] RE: if statement for empty cell
    By CLR in forum Excel General
    Replies: 0
    Last Post: 02-03-2006, 02:10 PM
  7. is statement with an empty cell as result
    By RDM in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-02-2005, 01:06 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