+ Reply to Thread
Results 1 to 15 of 15

Button to search for empty consecutive cells.

  1. #1
    Registered User
    Join Date
    09-29-2015
    Location
    Niagara Falls, NY
    MS-Off Ver
    10
    Posts
    9

    Button to search for empty consecutive cells.

    I have rows that represent units of time.
    In these rows each cell represents a segment of time.
    I also have columns that represent people.
    In each cell that person either did something or nothing during that time period.
    If the cell has a string in it that person did something during that time represented by the string. if the cell is blank that person did nothing.
    I need to make sure that nothing happened in at least 6 continuous cells of the selected cells.

    for example: each cell in a row is a 4hour period of time.. 6 cells in a row represent 24 hours.
    Tom in row A did nothing for 24 hours then did something for a few hours then nothing for a little while then something again.
    Lisa in row B did something but never did nothing for 6 continuous cells or 24 hours.

    I need be able to select a set of time(columns) and have the macro search through the rows in those columns and make sure that all the selected data has at least 6 empty cells in a row together.
    If a selection does not have 6 consecutive empty cells I need to return a message box saying that person did not have 6 empty consecutive cells.

    Tricky, Thanks in advance.

    Adam

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Button to search for empty consecutive cells.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  3. #3
    Registered User
    Join Date
    09-29-2015
    Location
    Niagara Falls, NY
    MS-Off Ver
    10
    Posts
    9

    Re: Button to search for empty consecutive cells.

    Thank you. I believe I have attached what your looking for.
    Attached Files Attached Files

  4. #4
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Button to search for empty consecutive cells.

    Test this.
    I select columns B:G and run the macro and it tells me employee 1 didn't have 6 consecutive cells empty cells.
    I don't know exactly how you are going to use this, so if it does something you don't like be specific about what you selected etc. and what it did. Specific, not I selected 8 cells and it didn't work. I selected cells (A1:G1) and it did this and I expected this to happen and why.
    Attached Files Attached Files
    Last edited by skywriter; 09-30-2015 at 05:39 PM.

  5. #5
    Registered User
    Join Date
    09-29-2015
    Location
    Niagara Falls, NY
    MS-Off Ver
    10
    Posts
    9

    Re: Button to search for empty consecutive cells.

    Thank you.

    I will have to test it later in the week. So give me a few days if possible? I basically run a small company and one of the overtime rules for employees is that they need to have 24 consecutive hours off in a week between 11pm Sunday night and 11pm Sunday night the following week. Making sure they have 24 consecutive hours off would mean that they have met the needs of this rule. On my real spreadsheet it would not say "WORKED" but it will contain their actual job assignments... some of the cells/time periods will have the letters "vs, ph, and nc." these represent employees being on vacation and personal holidays... If its possible I would like the macro to also skip cells with these letter and consider them also to be blank..

  6. #6
    Registered User
    Join Date
    09-29-2015
    Location
    Niagara Falls, NY
    MS-Off Ver
    10
    Posts
    9

    Re: Button to search for empty consecutive cells.

    I was able to test and it seems very close. however if I select several days B:AW, it does not find that Employee 3 had 6 consecutive empty cells (B:G).

    Error3.jpg
    Last edited by dam6952; 10-01-2015 at 09:04 AM.

  7. #7
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Button to search for empty consecutive cells.

    This was one of my concerns when I said I didn't know how you were going to use this. I considered this, but wrote the code so that if they work any hours during the period you select then it starts over with the counting. I thought your concern was their latest entries, not whether at anytime during the period selected on your sheet they had six consecutive blank cells. The other thing that can cause problems would be if you don't select a full day. In other words you select E:I which is partly in one day and partly in another. The code isn't segregating days. If you say I won't do that I will only select whole days and I am only concerned if they ever had six days during any of the whole days during the period I pick, then I will work under that assumption.
    Last edited by skywriter; 10-01-2015 at 01:00 PM.

  8. #8
    Registered User
    Join Date
    09-29-2015
    Location
    Niagara Falls, NY
    MS-Off Ver
    10
    Posts
    9
    The users will we able to select any period of time but generally they would be selecting 5 to 7 days worth of columns. having 6 consecutive blank cells, even if 3 are on one day and 3 are on the next is ok as 6 consecutive cells is still true. so possibly counters for blank and nonblanks cells??
    Last edited by dam6952; 10-01-2015 at 01:17 PM.

  9. #9
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Button to search for empty consecutive cells.

    So just a couple of things you should know about the code.
    I changed it so that as you add employees it will automatically adjust. This code assumes your employees are in column A and that the area below the employees in col A is clear all the way to the bottom of the sheet, no other data. It also assumes the employees start in row 5 as they do on your sample sheet. It's obvious where to change that if you move the first employee to a different row.
    So 5 is the starting row, the code checks for the last row with data in it in col A to decide where to stop that is the variable you see as lr.
    Here is that code. Also notice the worksheet name, change it to suit your actual sheet name, the quotes need to stay around the name. These are two separate lines is the code, I'm just drawing your attention to these lines. The code looks to see if the columns you selected intersect with any employee rows, so selecting data not on an employee row won't yield any results.
    Please Login or Register  to view this content.
    The code now looks for any six consecutive blank spaces within your selection. The counter starts at zero and adds 1 for each blank cell it finds. It resets every time it finds a cell that is not blank. If it reaches 6 it just moves to the next employee and you will not get a message box unless it actually finishes all selected cells for a given employee and hasn't reached 6, it may have reached 5 and then reset but since it never got to 6 you will now get a message. Bottom line 6 blank cells in a row anywhere in each row you selected and you get no message.
    Attached Files Attached Files
    Last edited by skywriter; 10-01-2015 at 08:49 PM.

  10. #10
    Registered User
    Join Date
    09-29-2015
    Location
    Niagara Falls, NY
    MS-Off Ver
    10
    Posts
    9

    Re: Button to search for empty consecutive cells.

    I think I got it. I wrote this before I seen your last reply. I also had to add an If statement that would skip blank is column A that are not real employees.

    Please Login or Register  to view this content.
    Last edited by dam6952; 10-02-2015 at 04:05 PM.

  11. #11
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Button to search for empty consecutive cells.

    Please click on the edit post button, select all of your code, then click the # icon and choose save changes.

    Code tags are required when posting code.

    Your code will go from this:
    Sub Test()
    End Sub

    To this:
    Please Login or Register  to view this content.
    Last edited by skywriter; 10-02-2015 at 02:15 PM.

  12. #12
    Registered User
    Join Date
    09-29-2015
    Location
    Niagara Falls, NY
    MS-Off Ver
    10
    Posts
    9

    Re: Button to search for empty consecutive cells.

    I did it! After further testing the code i made is slightly off. I will have to check out your new revision next week and get back to you. thank you for all your help!

  13. #13
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Button to search for empty consecutive cells.

    Quote Originally Posted by dam6952 View Post
    I did it! After further testing the code i made is slightly off. I will have to check out your new revision next week and get back to you. thank you for all your help!
    Good for you.
    Make sure to share the code that worked for you as this is a learning forum and those who peruse it with a similar need would like to see what worked.

    Then when you are happy with your solution.

    Please click the Thread Tools drop down box above your first post and choose solved.

    And if you are happy with my help then please consider clicking the add reputation button in the bottom left hand corner of any of my posts.
    Last edited by skywriter; 10-02-2015 at 04:25 PM.

  14. #14
    Registered User
    Join Date
    09-29-2015
    Location
    Niagara Falls, NY
    MS-Off Ver
    10
    Posts
    9

    Re: Button to search for empty consecutive cells.

    Your code is working perfectly. I wish I could have an explanation as to how it works. Thanks Again!
    Last edited by dam6952; 10-02-2015 at 11:57 PM.

  15. #15
    Registered User
    Join Date
    09-29-2015
    Location
    Niagara Falls, NY
    MS-Off Ver
    10
    Posts
    9
    Sometimes there is a blank in column a. Either an employee has left or a blank in a separates shift which is not a part of the example I gave you. If you need an example of this I can provide you with a larger example. Also in addition to blanks being counted as days off, I need to include the letters NC, ph, and vs anywhere in the cell also as blank... So the cell my have letters in the cell, which means they worked but if it's blank, or has abcvs, adcph or lmnnc, in the cell it should also count as blank. Is this possible?
    Quote Originally Posted by skywriter View Post
    So just a couple of things you should know about the code.
    I changed it so that as you add employees it will automatically adjust. This code assumes your employees are in column A and that the area below the employees in col A is clear all the way to the bottom of the sheet, no other data. It also assumes the employees start in row 5 as they do on your sample sheet. It's obvious where to change that if you move the first employee to a different row.
    So 5 is the starting row, the code checks for the last row with data in it in col A to decide where to stop that is the variable you see as lr.
    Here is that code. Also notice the worksheet name, change it to suit your actual sheet name, the quotes need to stay around the name. These are two separate lines is the code, I'm just drawing your attention to these lines. The code looks to see if the columns you selected intersect with any employee rows, so selecting data not on an employee row won't yield any results.
    Please Login or Register  to view this content.
    The code now looks for any six consecutive blank spaces within your selection. The counter starts at zero and adds 1 for each blank cell it finds. It resets every time it finds a cell that is not blank. If it reaches 6 it just moves to the next employee and you will not get a message box unless it actually finishes all selected cells for a given employee and hasn't reached 6, it may have reached 5 and then reset but since it never got to 6 you will now get a message. Bottom line 6 blank cells in a row anywhere in each row you selected and you get no message.

+ 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. Replies: 1
    Last Post: 04-18-2015, 09:04 PM
  2. [SOLVED] Toggle Button to filter empty cells or cells with values
    By goomblar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-05-2014, 10:31 AM
  3. Macro to skip header and search for non empty cells
    By AS147 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-11-2014, 10:00 AM
  4. Replies: 2
    Last Post: 07-25-2013, 01:01 PM
  5. Counting consecutive empty cells on the same row in a macro
    By Adam Brave in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2012, 01:33 PM
  6. search for non empty cells in a collumn and put a border on top
    By websqa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-07-2005, 06:01 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