Excel365 'Sequence' combined with 'If' - excel

I've created a sequence of dates for a dynamic calender.
This works fine.
But now I want to implement a condition, using 'IF' statement, where the step of the sequence is changed based on the value in the cells in column D (starting in cell D8).
If the cell in column D contains "Y" then the step in the sequence for that specific cell must be 8 in stead of 7.
The idea is that the sequence generates a list of all Mondays of a specific year (defined in B6), but when the Monday is a holiday, the return value must be a Thuesday.
The problem is that the reference for the column (D8) doesn't change and stays on the first cell reference. It should change to D9 for the next sequence value, D10 for the 3rd sequence value, etc.
Dutch formula -
=REEKS(54;1;DATUM($B$6;1;1)-WEEKDAG(DATUM($B$6;1;1);2)+1;ALS(D8="Y";7;8))
English version formula -
=SEQUENCE(54,1,Date($B$6,1,1)-WEEKDAY(DATE($B$6,1,1),2)+1,IF(D8="Y",7,8))
Edit 04/01/2023
This is the first cell in the sequence
This is currently the second cell in the sequence, where reference to D8 needs to be D9

Now I understand your question (in my first answer, I thought you were copying your formula on another place).
There seems to be a difference between earlier Excel versions, where a formula could only have one single cell as a result. Now there are formulae (like =SEQUENCE(), whose answer spreads over different cells. All those cells contain one element of the formula result, which means that the formula itself does not change over the multi-cell result.

I'm not sure if I understand what you mean: I have copied your formula (the English one) in cell "E2" and this is what I get:
=SEQUENCE(54,1,DATE($B$6,1,1)-WEEKDAY(DATE($B$6,1,1),2)+1,IF(D8="Y",7,8))
In another cell ("G3"), this turns into (select cell "E2", press Ctrl+C, press cell "G3", press Ctrl+V):
=SEQUENCE(54,1,DATE($B$6,1,1)-WEEKDAY(DATE($B$6,1,1),2)+1,IF(F9="Y",7,8))
So, when I apply a formula to another cell (two columns further, one row further), the reference to "D8" turns into "F9" (two columns further, one row further).
The other reference ("$B$6) does not change. Obviously, because the dollarsigns prevent that value to be changed (this is exactly what absolute and relative cell references are about, as described here).
Unfortunately, I don't know what you mean when you say that your cell references don't change: the ones, who should, do, and the ones, who shouldn't, don't, which is correct behaviour.
Oh: when you enter your formula in an external tool (like Notepad or so), you paste your formula in a cell and you paste it again in another cell, Excel won't realise that the cell references need to be update, is this the problem you're having?

Related

Question Regarding Microsoft Excel Problem Solving Problem - Why is the "2" in "$B2" also considered an absolute reference?

I am currently taking a Coursera course titled, "Everyday Excel, Part I" on Coursera. I was working on a quiz in the course and came across the following question:
Question 1
What will happen in the following spreadsheet setup if we: 1) Press Enter, 2) copy the formula in cell B3 using Ctrl-C (or Copy), and 3) paste the formula into cell A3? What value will result in cell A3? NOTE that this question is NOT asking for the value in cell B3!
Imaged referenced in Excel Problem
The choices are:
A. 11
B. 9
C. 3
D. 5
E. 6
I selected Choice D. 5, which is incorrect. The explanation for why this answer was as follows:
"I​ncorrect. In cell B3, the C$3 and $B2 are both mixed references. If we copy the formula in cell B3 and paste it in cell A3, then we will move all relative references in that formula over to the left one column. But, any relative row references will remain the same. Thus, C$3 in the copied formula will become B$3, but $B2 will remain B$2 since it has an absolute column reference. Therefore, the formula in cell A3 will be “=B$3-$B2”. The value in cell B3 will be 5 (7 – 2). Thus, the value in cell A3 will equal 5-2 = 3."
The correct answer is 3. However, is there a reason why the 2 in "$B2" is also an absolute reference? I thought that only portions of the reference that came after the "$" sign were considered absolute references. Any input regarding this would be much appreciated. Thanks so much!
If you put the dollar sign ($) before the column ($C1) then no matter what the column stays the same, meaning if you shift it one column to the right, it's going to stay $C1, but if you shift it one row downwards, it's going to change its row $C2.
If you put the dollar sign ($) before the row (C$1) then no matter what the row stays the same, meaning if you shift it one row downwards, it's going to stay C$1, but if you shift it one column to the right, it's going to change its column D$2.
So, in your example the reason why $B2 doesn't change is because the column is fixed and also there is no change in rows, so there is no reason to expect the column or the row to change, since whenever you change columns, rows won't change and vice versa.

OR in conditional formatting formula brakes condition giving unexpected outcome

I have a very unexpected outcome of OR used in conditional formatting formula.
Take a simple sheet:
Now add conditional formatting with formula:
=B4:G7=$A$1
It works as expected, with true value for cells containing "A"
Now try another formula:
=OR(B4:G7=$A$1;FALSE)
Which should basically mean the same. Well.. the outcome is very different:
What's even more confusing is that chaging, for example, cell I7 to "a" influences the outcome:
This is exact formula I have used, with "LUB" being "OR", and "FAŁSZ" being "FALSE":
Edit:
I forgot to stand the question. Question is: why does it happens? How do I use OR correctly in that context?
First, you need to understand how absolute and relative reference works in conditional formatting. Formula references refer to the very top left cell in the applies to range. If the formula has relative references, then for each applies to cell the cell in the formula reference shifts accordingly, if absolute - then the reference does not change. In your case, the formula =B4:G7=$A$1 is applied to cell B4, to cell C4 - =C4:H7=$A$1, to cell B5 - =B5:G8=$A$1, the same thing happens with formula =OR(B4:G7=$A$1;FALSE).
Second, the formulas =B4:G7=$A$1 and =OR(B4:G7=$A$1;FALSE) work completely differently. The first case actually compares the first cell of the range with $A$1, i.e. in the previous example =B4=$A$1, =C4=$A$1, B5=$A$1. In the second case, the range is divided into cells, they are compared with $A$1 and the results are passed to the OR function, i.e. =OR(B4:G7=$A$1;FALSE) => =OR(B4=$A$1;C4=$A$1;D4=$A$1 ... G7=$A$1;FALSE) and if even if one is TRUE, then you also get the resulting TRUE.
Consequently, we can conclude that the following formula will work correctly for you in this case:
=OR(B4=$A$1;FALSE)

How to define a range, using an Excel formula

In order to do some calculations on averages and differences of values in columns, I've defined a name, based on a range, but it seems to be completely going berserk:
I have a cell (D13), defined as Header_First _Answer, which contains the title of the column, and I have a value (currently being 69), which contains the number of entries, called Total_Count.
I've defined the entries of that column as another name: "All_First_Answered_Dates", defined as =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0) (start by the first entry under Header_First_Answer, take up to 69 entries, and define a range out of this).
In cell G5, I'm using that name in order to do some calculations (calculating averages), but this seems not to work (there is a #Value error).
After second comment from Rory: G5 formula and first formula evaluation result:
Formula:
=AVERAGE(IF(ISBLANK(All_First_Answered_Dates);TODAY();All_First_Answered_Dates) - All_Start_Dates)
First evaluation result:
=AVERAGE(IF(ISBLANK(#Value!);TODAY();All_First_Answered_Dates) - All_Start_Dates)
Hence, my conclusion:
After some checking I've found out that this is due to the name "All_First_Answered_Dates", which seems to be interpreted one time too many (or how do I explain this):
In different cells, I've entered the formula =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0) (which is exactly the meaning of "All_First_Answered_Dates"), and every time, using the Evaluate Formula feature, I see that the last but one result is correct: $D$14:$D$82. However, after that, another evaluation is done, turning this value into 43283 (in case the formula is entered in "J14"), 43300 (in case the formula is entered in "J15"), ..., and in case I enter this formula in a cell with row number lower than 14, I have the error value #Value (which explains the wrong result in cell G5).
If I simply put the formula =$D$14:$D$82 in any of the mentioned cells, then the content of some cells in column D are shown (which are dates, not values like 43283 or 43300).
It appears that declaring a range as =x:y, where x and y are formula results, is not working.
Does anybody know how I can define a range as a formula, which I can then use in order to define in a name?
I can imagine my explanation being quite complicated without an image, hence the attached screenshot. In there:
In cell J13, there is the formula =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0).
In cell J14, there is the same formula.
In cell K14, there is the formula =$D$14:$D$82.
For completion purposes, hereby a screenshot of the name manager, containing both mentioned names (the ones, selected in the name manager):
Edit after first comment:
The idea behind the range is the following:
1. Take the first row under Header_First_Answer, do not take any other column : OFFSET(Header_First_Answer;1;0)
2. Take the Total_Count's row under Header_First_Answer, do not take any other column : OFFSET(Header_First_Answer;Total_Count;0)
3. Define a range, based on those two cells, by putting a semicolon between them.
I was not aware of the height and width features of the Offset() worksheet function. I've implemented them, which makes the formulas much easier.
Unfortunately the problem still persists.
Thanks in advance
Dominique
I've just found the answer of what was going wrong:
The formula was meant to be an array formula. Something went wrong and while trying to debug, I accidently re-formatted the formula into a normal formula (I must have pressed "ENTER" instead of "Ctrl" + "Shift" + "ENTER") at some point.
I have re-applied array formula (using "Ctrl" + "Shift" + "ENTER"), getting a formula like:
{=AVERAGE(IF(ISBLANK(All_First_Answered_Dates);TODAY();All_First_Answered_Dates) - All_Start_Dates)}
(mind the braces {, })
Now everything is working fine.

Increment value inside curly brackets

I am using a formula in Excel 2010 to display the individual with the most wins, as below:
IF($P$3="Most wins",SUM(LARGE(Wins,{1})),"FALSE")
where wins represents an array of an indefinite number of individuals.
However I would like to be able to autofill this, or similar, such that the next row displays the following:
IF($P$3="Most wins",SUM(LARGE(Wins,{2})),"FALSE")
Unfortunately I can't get the value inside the curly brackets to increment, which is causing no end off issues when the formula is going to be dragged down beyond 1,000 rows.
Is this possible, or am I using the wrong method?
=IF($P$3="Most wins",SUM(LARGE(Wins,ROW(A1))),"FALSE")
Place that in the top of your column and copy it down. As you do, the cell reference for A1 will change from A1 to A2 to A3, etc. The ROW function returns the number of the row of the cell reference.
Alternatively as pointed out in Darren's comment, you could also use ROW()-2 if you data is starting in the second row. This has the advantage if you ver deleted the 1 row or column, you will not screw up your cell references.

Authoritative Excel range syntax reference

Sorry if this has been asked before but I can't find it. I am looking for an authoritative description of all valid strings that can be used as a reference, e.g., "A1:C5", "$A:$A", $A2" etc etc. That seems a pretty basic thing yet I've wasted hours trying to locate it. All I can find is a swamp of "helpful" examples but no reference.
This seems like a fun exercise. I'm going to list as many as I can, and hopefully other people could point out ones that I've forgotten/missed/didn't know about.
A sort-of guide to what you're asking for, and a source for anyone looking for additional documentaion: http://www.excelfunctions.net/Excel-Reference-Styles.html
I'm going to start with 5 broad categories - A1, R1C1, Table, Formulas, and VBA references. I'm going to ignore other programs that can interact with Excel for the moment (Although I might add in Python if that's officially added in)
All examples will be using A1 reference style, since they're more intuitive for an inexperienced user.
A1 Reference type:
A1 style tells us the coordinates of a given cell. The alphanumeric portion tells us which column we're in, while the numeric portion tells us which row we're in.
Cell References:
A1 - The basic cell reference. References the cell A1, and as you drag formulas through columns and rows, it'll change. For example, if your formula is in C1, and you move it to D2, it'll now reference B2.
Good use: Comparing two sheets to each other. ='Sheet1'!A1='Sheet2'!A1 will compare the data in sheet 1 to sheet 2, and give a true/false if they match or not. Formula can easily be slid sideways and up/down for additional comparisons.
$A1 - This locks the column. As you drag formulas, the row will change, but the column won't. Useful if you always want to reference the same column in a formula. For example, if your formula is in C1, and you move it to D2, it'll now reference $A2.
Useful example: Formulas in helper columns. A1 = $C1*2 will neatly slide down without any issues, and if you move it over to the B column, it'll continue to reference C.
A$1 - This locks the row. As you drag formulas, the column will change, but the row won't. Useful if you always want to reference the same row in a formula. For example, if your formula is in C1, and you move it to D2, it'll now reference B$1.
$A$1 - This locks the cell reference. No matter how you drag the formulas around, it'll continue to reference cell A1. For example, if your formula is in C1, and you move it to D2, it'll now reference $A$1.
Useful example: Constant multiplier for all numbers.
To summarize, A1 References are broken out as follows:
Alphanumeric portion - What column we're in
Numeric portion - What row we're in
$ - Locking the portion immediately following
Range References:
Due to the sheer number of combinations of range references, I'm sicking to the most common. Mixing and matching types of cell references with types of range references will get every combination.
A1:B2 - References the grid of cells with A1 being at the top-left, and B2 being at the bottom-right. Both parts of the formula will slide when moved. It's generally recommended not to have unlocked references in formulas applied over multiple cells, since the reference range will also move. For example, if you have =Sum(A1:B2) in C1, and you move it to D2, it will transform to =Sum(B2:C3).
Unlocked range references most often cause problems in vlookup formulas, where the reference range ends up changing as people slide the formula down.
$A$1:$B$2 - References the grid of cells with A1 being at the top-left, and B2 being at the bottom-right. This range reference won't change, even when moved. For example, if you have =Sum($A$1:$B$2) in C1, and you move it to D2, it will transform to =Sum($A$1:$B$2)
$A$1:A2 - This locks the first cell, but leaves the second part of the reference flexible. This is very useful when you want to see "Everything that's happened so far"- For example, if you're numbering a list, when combined with =countifs ("What instance of occurrence is this one?") For example, if you have =Sum($A$1:A2) in C1, and you move it to D2, it will transform to =Sum($A$1:B3)
Similar effects can be used with $A$1:B1 going horizontally.
A:A - This gives the entire column A. Since this is unlocked, it'll slide. Useful for grabbing everything in a given column. For example, if you have =Sum(A:A) in C1, and you move it to D2, it will transform to =Sum(B:B)
$A:A - This gives the entire column A. This will expand as you go across to grab more columns. I can't think of an immediate practical use for it. For example, if you have =Sum($A:A) in C1, and you move it to D2, it will transform to =Sum($A:B)
$A:$A - This gives the entire column A. This is locked to column A, even if you move the formulas around. For example, if you have =Sum($A:$A) in C1, and you move it to D2, it will stay as =Sum($A:$A)
Slightly lesser known are rows:
1:1 - The entire first row. Unlocked. For example, if you have =Sum(1:1) in C2, and you move it to D3, it will transform to =Sum(2:2)
$1:1 - The entire first row. Partially locked. For example, if you have =Sum($1:1) in C2, and you move it to D3, it will transform to =Sum($1:2)
$1:$1 - The entire first row. Completely locked. For example, if you have =Sum($1:$1) in C2, and you move it to D3, it will stay as =Sum($1:$1)
R1C1 References
R1C1 is more of a reference style as opposed to a coordinate style. This can be extremely useful, since your formulas in all of your cells look exactly the same, and makes entering sliding formulas in VBA significantly easier.
R1C2 is broken down as such:
R - Rows
1 - Row 1 OR
[1] - We're 1 row down from our current cell
C - Columns
1 - column 1 OR
[1] - We're 1 column over from our current cell
In other words, if you don't have brackets, you're referencing the cell or column in question. If you do have brackets, you have a relative reference.
Cell References:
R3C7 is an absolute reference - 3rd row, 7th column. This would be the same as saying $G$3 in A1 style, as detailed above.
R[3]C7 is partially absolute, partially relative reference. This is asking for "Give me the cell 3 rows down from the current cell, in column 7" (Which is column G) If I have this in cell A1, I'd be referencing cell G4. If I move it to cell B2, I'd be referencing cell G5.
R[2]C[-2] is a full relative reference. You can also reference earlier columns or rows, as indicated by the - sign. If I had this formula in cell C1, it would be referencing cell A3. If I move the formula to D2, I would now be referencing cell B4.
Range references:
Table References
Tables make referencing other cells and ranges easy and intuitive. They're broken out as follows:
TableName[ColumnName]
Formula References
VBA References
VBA Conversion from Letter to Column
Something that's come up a few times is changing column numbers to column letters. I found this very helpful piece of code (somewhere on Stack Overflow, I don't currently have the link handy) to convert column numbers to column letters for ease of use in VBA.
Function Col_Letter(lngCol As Long) As String
'Converts a number (usually generated from an application.match function) to a letter. For example 1 turns into A, 5 turns into E, etc.
Dim vArr
vArr = Split(Cells(1, lngCol).Address(True, False), "$")
Col_Letter = vArr(0)
End Function
Under Construction*
I don't know if there is a list of formats, because there really are only 2: A1 format and R1C1 format.
You're not actually specifying a range format when you use A1:C3 because the : is actually the range operator.
The variants of $A$1, $A1, A$1 are just that - variants, identifying that when copying the reference the coordinate before the $ should not change, but that otherwise the coordinate may change relative to the copy.
R1C1 is more complex, because it allows relativity. R3C2 is an absolute reference to Row 3, Column 2 (B3 in A1 notation), while the use of braces [] in an R1C1 reference indicates that it is relative to the current cell R[-2]C[1] from cell R3C2 would give R1C3 (C1).
Nearly forgot. There can also be a reference to cells in another worksheet. 'Sheet2'!IV256
I use
(((\w*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d+)
as a regexp for identifying cell references in the A1 format
The problem is that there are a variety of operators (Range, Intersect, implicit intersect etc ), functions (INDEX, OFFSET, CHOOSE, INDIRECT + user-defined functions), Defined Names and structured Table references etc that can all be de-referenced to provide a valid range reference. So to do a complete job means parsing arbitrary Excel formulae.
And it also varies by Excel version.
If all you want to do is work with standard explicit range references the usual trick is to convert the string to R1C1 notation and work with that. The syntax for R1C1 references is reasonably well described in Excel documentation.
There is also a BNF description of Excel formulae available somewhere but I have mislaid the reference.
"it's used for identifying cell references that might need modification when inserting a new row or column in a worksheet"
If the rows/columns are inserted with Excel live (as opposed to hacking into the workbook using another application), any references will update to the new address automatically.

Resources