I am able to use a formula to calculate the mondays in a month when the user enters a date, example, entering July 10, 2019, states that 3 mondays are left within that month which is correct, but i need to set a range of cells with that formula and i am trying to use VBA to do so, but it gives a 1004 error. I assume its because of the quotation marks "" needed for the INDIRECT function. I have used other formulas such as SUM without any issues.
This if the full formula:
Range("E17:E" & 17 + amount).Formula = "=IF(" & "L17<>0,IF(OR(SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(L17&":"&EOMONTH(L17,0))))=2)) > 4,AND(SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(L17&":"&EOMONTH(L17,0))))=2))=4,$M$1=4)),((J17*12)/52),0), ((J17*12)/52) )
This is the Portion that calculates the remaining mondays
SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(L17&":"&EOMONTH(L17,0))))=2))
This if the full formula:
Range("E17:E" & 17 + amount).Formula = "=IF(" & "L17<>0,IF(OR(SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(L17&":"&EOMONTH(L17,0))))=2)) > 4,AND(SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(L17&":"&EOMONTH(L17,0))))=2))=4,$M$1=4)),((J17*12)/52),0), ((J17*12)/52) )
This is the Portion that calculates the remaining mondays
SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(L17&":"&EOMONTH(L17,0))))=2))