Find n number of consecutive zeros between two dates

Newcook

New Member
Joined
Aug 10, 2021
Messages
10
Office Version
  1. 365
Platform
  1. Windows
I have a schedule to find available rooms for a number of people on work rotations from a number of possible rooms. I was able to add all of the occupancies in rows 124 to 128 where each row represents the occupancy of a particular room, so zeros indicate available space in each room. I found this formula from another thread: =ADDRESS(ROW(O$124),COLUMN(O$124)-1+FIND(REPT(1,$A$149),CONCAT(IF($O$124:$JF$128=0,1,0))),4) that gives me the first instance of n number of consecutive zeros in O124:JF128, however, I am looking to find the first instance but between a start date in B149 and end date in C149. n is in A149, the dates are in O4:JF4. Once I have the first instance, from the row number I can identify which room to put a person in.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
This is a recap of the discussion in another thread. With the dates like so:

Book2
ABNOPQRSTUVWXYZAAABACADAEAF
41/11/20211/18/20211/25/20212/1/20212/8/20212/15/20212/22/20213/1/20213/8/20213/15/20213/22/20213/29/20214/5/20214/12/20214/19/20214/26/20215/3/20215/10/2021
Sheet4


And the rest of the range like this:

Book2
ABNOPQRSTUVWXYZAAABACADAEAF
124123014600000000129
1254570000062189330000
12677880000000123456800
127000123090978000000
128LengthStartEnd808000088888888888
14972/1/20214/1/2021
150
151Cell:$Q$126
Sheet4
Cell Formulas
RangeFormula
B151B151=ADDRESS(ROW(O124)-1+MATCH(MIN(IFERROR(FIND(REPT("0",A149),MID(CONCAT(IF(O124:JF128=0,"0",".")),SEQUENCE(ROWS(O124:JF128),,1,COLUMNS(O124:JF128)),COLUMNS(O124:JF128))),"")),IFERROR(FIND(REPT("0",A149),MID(CONCAT(IF(O124:JF128=0,"0",".")),SEQUENCE(ROWS(O124:JF128),,1,COLUMNS(O124:JF128)),COLUMNS(O124:JF128))),""),0),COLUMN(O124)-1+MIN(IFERROR(FIND(REPT("0",A149),MID(CONCAT(IF(O124:JF128=0,"0",".")),SEQUENCE(ROWS(O124:JF128),,1,COLUMNS(O124:JF128)),COLUMNS(O124:JF128))),"")))


The B151 formula should solve the problem, except for the matching the date part. I also offered this version of the formula using LET:

Excel Formula:
=LET(rng,O124:JF128,r,ROWS(rng),c,COLUMNS(rng),tl,INDEX(rng,1,1),fa,IFERROR(FIND(REPT("0",A149),MID(CONCAT(IF(rng=0,"0",".")),SEQUENCE(r,,1,c),c)),""),ADDRESS(ROW(tl)-1+MATCH(MIN(fa),fa,0),COLUMN(tl)-1+MIN(fa)))

Full disclosure, I don't actually have LET to test with, so that's a bit theoretical. But if my LET logic is sound, then this version:

Excel Formula:
=LET(rng,INDEX(O124:JF124,MATCH(B149,O4:JF4)):JF128,r,ROWS(rng),c,COLUMNS(rng),tl,INDEX(rng,1,1),fa,IFERROR(FIND(REPT("0",A149),MID(CONCAT(IF(rng=0,"0",".")),SEQUENCE(r,,1,c),c)),""),ADDRESS(ROW(tl)-1+MATCH(MIN(fa),fa,0),COLUMN(tl)-1+MIN(fa)))

should handle the date requirement too. It'll take a lot more work to retrofit that change into the original formula, but I'll look at that when I have the change, if the LET is not successful.
 
Upvote 0
Solution
Wow, thank you Eric, I tried assigning a room with your LET formula above and it was right on. I'll have to try with a few other rooms to be sure, but it looks like it will work. I'll post again later when I've tried a few more.
 
Upvote 0
I just assigned 16 rooms in a matter on minutes. the thing that took the longest is trying to remember which room number each line represents. I've actually extended it to 20 rooms because that is how many we have. I had to make a screenshot of what row belongs to which room because I couldn't remember them once I got past the first five, ha,ha. But it worked absolutely perfectly for all 16 rooms. You have no idea how much time you just saved me. Thank you so much.
 
Upvote 0
Woohoo! Glad it works for you. That was actually kinda fun to figure out. (Also a shout out to @Peter_SSs since his basic idea is at the core of the function.) :biggrin:

the thing that took the longest is trying to remember which room number each line represents
I wondered about that. Instead of returning the row number, you could put the room number in column N (for example), and have the formula return the room number? And maybe the date instead of the column number? Or do you need the cell address so you can go to that spot and update the cells to show they're now assigned? I wonder if HYPERLINK works in LET, so you can just click on it to go to that cell.
 
Upvote 0
I really only need the room number, and the house name. I could add the room number next to each row. I already have a formula that takes care of the rest. There are 5 rooms per house, so the first 5 rows (124 to 128) belong to one house, the next 5 rows (129 to 133) to another, etc.
 
Upvote 0
So I entered the row number in JH124 by using the ROW() function, then in JI124 the house name and in JK124, the room number, and so on for all the rows. Then I did an index and match which works well but I'm not sure how to get the row from the let formula. I tried making another column with RIGHT function for last three digits, but my index and match didn't like that.
 
Upvote 0
Try using RIGHT(xxx,3)+0 to get the last three digits. If you just use RIGHT, the result will be a text value, and the MATCH function will not match that with a numeric value. When you add 0 to a number stored as text, it coerces it back to a numeric value, which should match ok.
 
Upvote 0
Yay, that worked. Thank you. I was able to assign 36 rooms this morning by hand typing the three digits. That would normally have taken me hours to do. Have a little over a hundred to do this season. Will be great to start with this next season.
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,638
Members
449,093
Latest member
Ahmad123098

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top