Explain this formula

Joined
Jul 23, 2010
Messages
6
"{=IF(MONTH(DATE(YEAR(AA3),MONTH(AA3),1))<>MONTH(DATE(YEAR(AA3),MONTH(AA3),1)-(WEEKDAY(DATE(YEAR(AA3),MONTH(AA3),1))-1)+{0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}-1),"",DATE(YEAR(AA3),MONTH(AA3),1)-(WEEKDAY(DATE(YEAR(AA3),MONTH(AA3),1))-1)+{0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}-1)}"


Hi Guys, i am an intermediate on excel. However recently came across this formula, could you please explain what the {0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}-1) part is doing here. I havent come across this before.

AA3 is a reference which looks up a static 1st of the month date (01/07/2010) which i populate. The clever thing about this formula is as i change the month this formula is the same in all 30 cells of a grid, however the values are different, it populates that months dates

Could anyone help here.

Thanks

Will
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

barry houdini

MrExcel MVP
Joined
Mar 23, 2005
Messages
20,825
Hello Will, welcome to MrExcel

As you say the formula creates a grid of consecutive dates, this is a type of array formula that returns an array of values and needs to be entered into an array of cells of the corresponding size. This part

{0;1;2;3;4;5}

effectively defines the depth (6 rows) and this part

{1,2,3,4,5,6,7}

the width (7 columns) so what you end up with is a grid of 42 consecutive dates (which cover the month in question and some dates either side), or you would but the IF part checks whether each date is in the relevant month and shows a blank if it isn't. Although the formula generates dates you would usually custom format these as d to show just the day of the month.

If AA3 always contains the 1st of the month (or if you can make it do that) then formula can be simplified to

=IF(MONTH(AA3)<>MONTH(AA3-WEEKDAY(AA3)+{0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}),"",AA3-WEEKDAY(AA3)+{0;1;2;3;4;5}*7+{1,2,3,4,5,6,7})
 
Last edited:
Joined
Jul 23, 2010
Messages
6
Thanks Barry, makes perfect sense. One last point, when i move this grid to another place, with the same formula's, looking up the same static cell, formatted the same, and arrayed - the values disappear. Do i have to make name a range for this array, or format this area uniquely?

Thanks

Will
 

barry houdini

MrExcel MVP
Joined
Mar 23, 2005
Messages
20,825
You have to enter the formula in the correct manner. Paste the formula into the top left cell of the grid you want, then select the whole 6 row x 7 column grid with the top left cell the "active cell". Press F2 then hold down CTRL+SHIFT and press ENTER.

Note that you don't use CSE until you've selected the whole range
 
Joined
Jul 23, 2010
Messages
6
Houdini, there is no illusion in your explanation. Easy to understand, and thus implement. I appreciate it alot, would like to return the favour at some point; but unfortunately i think we both know the great houdini doesnt need assistants.

Cheers mate

Will
 

Watch MrExcel Video

Forum statistics

Threads
1,109,507
Messages
5,529,268
Members
409,859
Latest member
emperorgenghiskhan
Top