Find row number of next instance of specific value - excel

I have a column of days of the week in an Excel 2008 spreadsheet. In another column, I want to execute code that involves the Friday in the current row and its following Friday further down in the column. The problem is, it's five years of data that lists the days consecutively for most weeks, but sometimes there's a day missing in the week due to holidays. Hence I can't reference a fixed number of cells away to compare data from Friday to Friday.
So I'm looking for a means of doing the following pseudo-code:
=if(xcell = "Friday" and the_next_cell_named_Friday_down_in_the_list = "Friday", do "code that works with the row xcell is in and the row the next Friday cell is in")
I know there's a way of doing it, but I can't quite see how to execute it.
(If it's not too hard to answer this as well, I also want to be able to do the same thing as above, except check the Friday after the next (every two weeks).)

Use VLOOKUP to find the next "Friday" down in the column of days. E.g.: if column of days is column A, and the row you are currently on is 4, while the last row in column A is 86523, then the correct formula to find the next "Friday" is:
VLOOKUP("Friday", A5:A86523, 1, FALSE)
However this will give you back "Friday" if there is a next "Friday" after row 4, and will give you #N/A error if there isn't - not very useful. You can manipulate table_array (A5:A86523), or index_number (1) to get back something more useful.
For help on the VLOOKUP function click here.

=match("xyz",a1:a3,0)
appears to do it

OP's own answer will not "copy down" so I suggest:
=IF(A2="Friday",MATCH("Friday",A3:A$20,0)+ROW(),"")
Extend range limit to suit.

Related

Excel increment cellsand skip weekends or holidays

I had a google sheet that I am trying to translate to an excel file. The original formula is this:
=Arrayformula(if(J2:J<>"", regexreplace(J2:J, "[^A-Z]",), if( (weekday(B2:B) = 1)+(weekday(B2:B) = 7), ,countifs (weekday(B2:B), ">1", weekday(B2:B), "<7", J2:J, "", row(B2:B), "<="&row(B2:B)))))
I am looking to convert this to something in excel. Basically the idea behind this formula was that it would count down a column (A) looking at the next column (B) to see what the date was. If it was a weekend, it would skip the increment. If it was a work day, it would increment. This allowed me to automatically count down 20 work days for a sprint. Then it would look at a 2nd column (J) for any Notes in that column. If anything was in the column, it would skip that increment and put a letter in that row (column A). For example, if I put "Holiday" in column J, it would be an "H" in that row in column A. That way I could still count down to plan out 20 work days easily.
It worked fine in Google Sheets, but the translation to Excel was not as easy as I would have hoped.
You can use WEEKDAY.
For example, based on your description you could try:
=IF(OR(WEEKDAY(G2)=1, WEEKDAY(G2)=7), "",
IF(ISBLANK(H2)=FALSE, H2,
MAX(F$1:F1)+1))
EDIT as suggested by #Marti:
A much cleaner way is to use a second argument in the WEEKDAY function, and then cut down on the number of characters in the second IF.
=IF(WEEKDAY(G2, 3)>=5, "",
IF(ISBLANK(H2), MAX(F$1:F1)+1, H2))

Finding data for a determined week

I have a table and I have a date in cell B4 which is something like 15/03/2021
I want to count values where the start date is the value on cell B4 but also count everything till the end of that week. So everything from Monday 15/03/2021 to Sunday 21/03/2021
What I have so far is something like
=COUNTIFS(MySheet!A:A,"Y",MySheet!C:C,">="&B4)
My trouble is how to tell it "also count everything until sunday that week without having to manually put the end date into a cell
Add 6 to the value in B4 to get the second criteria.
=COUNTIFS(Mysheet!A:A,"Y",Mysheet!C:C,">="&B4, Mysheet!C:C,"<="&B4+6)
I assume the question behind your question is how to account for dates in B4 other than a monday and keep counting untill the end of that same week, therefor you can use:
=COUNTIFS(Mysheet!A:A,"Y",Mysheet!C:C,">="&B4,Mysheet!C:C,"<="&B4+7-WEEKDAY(B4,2))
This does set a Sunday as the "end" of the week as per your OP.
Your question is slightly ambiguous, so there are two possible answers
To count for exactly 7 days:
=COUNTIFS(MySheet!A:A,"Y", MySheet!C:C,">="&B4, MySheet!C:C,"<"&B4+7)
To count until the end of the next Sunday: (N.B. On Sundays, this will only count 1 day)
=COUNTIFS(MySheet!A:A,"Y", MySheet!C:C,">="&B4, MySheet!C:C,"<"&B4+8-Weekday(B4,2))
This works by saying "on or after (>=) the date given", and "before (<) 7 days later / the following Monday"

Finding the last occupied cell using a formulae

This formulae "works", but it seems a bit long winded. Can anyone suggest an "easier" formulae. It returns the value in the 5th Column to a date in the 1st column which is called from a separate (and discrete) worksheet. If there is no data in the 5th column (because we haven't reached or passed that date), then the latest available data is called ($A$20, is the "calling date, on a current worksheet):-
IF(VLOOKUP($A$20,'[FTSE100.xlsx]Meteor Step Down
Plans'!$A$18:$E$2828,5)="",VLOOKUP(HLOOKUP(A20,'[FTSE100.xlsx]Meteor Step
Down Plans'!$A$18:$A$2628,MATCH(TRUE,INDEX(ISBLANK('[FTSE100.xlsx]Meteor
Step Down Plans'!$E$18:$E$2828),0,0),0)-1),'[FTSE100.xlsx]Meteor Step Down
Plans'!$A$18:$E$2828,5),VLOOKUP($A$20,'[FTSE100.xlsx]Meteor Step Down
Plans'!$A$18:$E$2828,5))
The formula is in a different workbook to the data. The formula is used to determine the last value in an array, the first column of which is a date range (01/01/2000 to 31/12/2027....say) The required data is in column 5. Entries may be up to date (i.e. the last entry was made today, therefore it will pickup todays value. The last entry may have been several days (weeks) ago, therefore it will pick up the last value in the designated column (column 5). I don't see why it can't go into a named range, as the array size is fixed. Does that help?
Thanks Ron, nearly there. That works beautifully for "missing" dates in the array. i.e. when Saturday and Sunday dates are missing, it finds the value (in column 5) of the previous Friday. However (and there is usually a "however"), if $A$20 is a date in advance of the date of the last data in the array i.e. column 5 is blank at that date, your formulae returns 0 (zero), instead of the data as at the last date that data has been entered. i.e. enter 02/04/2018 and your formulae returns 0, not the data at the last date available 28/02/2018. Is that a little more clear?? (Thank you anyway, for spending the time - I'm still trying to work out how your formulae works as it does. Is the "/" significant (other than being a "divide by" symbol, if so it's something I've never come across before? Regards...........Mike. P.S. The dates in the array (Column 1) are all in from 2016 to 2027 (excluding weekend and bank holidays), and are arranged in ascending order i.e. from 01/01/2016 to 31/12/2027
Ron - Sorry mate, buy I can't see a "second" formulae???
If I understand what you want to do correctly, (and that is hard to do since you give NO examples of your data, actual output or desired output), try:
=LOOKUP(2,1/((myDate>=A:A)*(LEN(A:A)>0)),E:E)
If it is the case that you have dates in column A and no entries in Column E, then you might have to do something like:
=LOOKUP(2,1/((myDate>=A:A)*(LEN(A:A)>0)*(LEN(E:E)>0)),E:E)
Of course, you will have to modify the cell references and named range to refer to the proper workbooks and cell.
Possibly something like:
=LOOKUP(2,1/(($A$20>='[FTSE100.xlsx]Meteor Step Down Plans'!$A$18:$E$2828)*(LEN('[FTSE100.xlsx]Meteor Step Down Plans'!$A$18:$E$2828)>0)),'[FTSE100.xlsx]Meteor Step Down Plans'!$E$18:$E$2828)
This should return the item from Column E that is either at or above the same row as myDate in Column A. If myDate does not exist in column A, it will match the nearest earlier date in Column A and return from that row in Column E.
In the second version of the formula, it also checks that there is an entry in Column E matching the column A date, and, if not, it will look above.

forumla automatcally filled when another cell value is added - Excel

I have: =NETWORKDAYS(N25, AJ25-1) in Column O to calculate the number of busines days since an item has gone out of the building. right now I am manually duplicating it each time a new item goes out.
But is there a way to put a formula that when Column N is filled out, it will automatically added in the formula above in Column O respective to the row?
On that note, it seems my formula is a bit wonky. It works perfectly when it gets to the day AFTER it was sent out (day 1), but if it's sent out today, it will come back with the value -1 or -2 instead of "0" indicating that today's date (AJ25) is the same as the value I entered in on Column N.
I can understand why it does that but not sure how to calculate it so it doens't count today's date but starts the day after.
It seems #Jeeped's formula met the requirement:
=if(isblank($N25), "", NETWORKDAYS(N25, MAX(N25, AJ25))-1)

Countif function for multiple criteria

I am trying to create a formula in Excel that will count cells with 3 certain criteria. My example is below: cell M3:M350 is the name, cell Q3:Q350 is the date, cell R3:R350 is the current step. I need to know how many times the name Amanda shows up that is in the current step of Material Review, and that is also 30 days or less than the date in cell Q3:Q350. The formula I have been trying is:
=COUNTIFS('Active Projects'!M3:M350,"AMANDA MARTIN",'Active
Projects'!Q3:Q350,"<="&NOW+30,'Active Projects'!R3:R350,"*MATERIAL REVIEW")
The answer keeps giving me 0, and it should be 1.
Does anybody know the correct formula to use? It has been eating at me for a week now, and I have tried different variations, and still cannot get it to not count the dates older than 30 days from today.
please update your formula as follows:
=COUNTIFS('Active Projects'!M3:M350,"AMANDA MARTIN",'Active Projects'!Q3:Q350,"<=" & TODAY() + 30,'Active Projects'!R3:R350,"*MATERIAL REVIEW")
Structure you have used for date is not correct:
=COUNTIFS('Active Projects'!M3:M350,"AMANDA MARTIN",**'Active
Projects'!Q3:Q350,"<="&NOW+30**,'Active Projects'!R3:R350,"*MATERIAL REVIEW")
there should be brackets () after NOW or TODAY functions.

Resources