=IF(J4="Monthly",EOMONTH($R4,COLUMNS($H8:H8)-1)-MOD(WEEKDAY(EOMONTH($R4,COLUMNS($H8:H8)-1))+1,7))
Try this and copy towards right
This works for only months