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

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
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,602
Messages
5,512,348
Members
408,887
Latest member
KPH Akron

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top