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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,627
Messages
5,838,444
Members
430,548
Latest member
hh_dh2001

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
Top