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
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
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:
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

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