Google-sheets – Is any way to generate from word April 1/4/2020 – 30/4/2020

google sheetsgoogle-apps

I have a data validation cell (F4) with the 12 months, and I have this sumifs to search for certain dates, how can I change the dates based on the cells (F4)value?

=sumifs('sheet01'!C3:C; 
        'sheet01!D3:D; 
         "*"&B5&"*" ; 
        'sheet01'!B3:B ; "<= 1/01/2020"; 
        'sheet01'!B3:B ; ">= 31/01/2020" ) 

This is for Jan, but if I choose Feb (F4 Cell) to change the dates to 01/04/2020 -30/04/2020.
Is any way to do it?

EDIT: The link of the Spreadsheet (Tab: Anvil – 5%) :
https://docs.google.com/spreadsheets/d/11mFjBQfnxBztiSWuv4HgQCwe2ZhTJ_njhlLl1ZKOJmE/edit?usp=sharing

Best Answer

I made a duplicate of your "Anvil - 5%" sheet (renamed "Erik Help"). There, I first added data validation to F4 (as a list) so that you can only choose the three-letter English month names. This is an extra level of fool-proofing.

Your formulas in C12 and E12 are already set up to SUMIF only entries that fall between the dates in C7 and E7, respectively. So the only thing you really needed was a way to change those two dates to the beginning and ending of the month whose three-letter English month name is shown in F4.

However, you've set your locale to Greece, while your sheet is in English. This adds a layer of complexity, because month names will only be recognized in Greek. This being the case, I placed the following formula in C7:

=IFERROR(DATEVALUE(SWITCH(F4; "Jan"; "Ιαν"; "Feb"; "Φεβ"; "Mar"; "Μαρ"; "Apr"; "Απρ"; "May"; "Μαΐ"; "Jun"; "Ιουν"; "Jul"; "Ιουλ"; "Aug"; "Αυγ"; "Sep"; "Σεπ"; "Oct"; "Οκτ"; "Nov"; "Νοε"; "Dec"; "Δεκ")&" "&1))

IFERROR will return null should an error every occur. SWITCH will switch the three-letter English month name in F4 to the Greek equivalent. DATEVALUE forms a date from that three-letter Greek month name with " 1" added to it. This will always give the first of that month in the current year, since year is left off.

Once this date is in place, the formula for E7 can reference it in order to return the end of that month:

=IF(C7="";;EOMONTH(C7;0))

This simply says, "If C7 is null, do nothing; otherwise, return the end of the month that is zero months away from the date in C7 (i.e., the end of that same month).

Since I set up data validation in F4, it should be impossible for you to ever have anything in F4 that would trigger an error. But it's good practice to have IFERROR in place anyway, in case things change in the future.

One final note: I could have set up a new sheet with the English and Greek three-letter month names and then used VLOOKUP in the C7 formula. But since this is a closed set, I figured it would be easier for you to understand if I just used SWICH directly in the formula.