Get user input for month and year to populate cells with dates of that month and year in excel - excel

i want to take two inputs from user Year and month and then populate the cells with the dates of that month and year in excel.
for example:
Enter year:2017
Enter month:Jan
Date
1/1/2017
1/2/2017
1/3/2017
1/4/2017
.
.
.
.
the cells should auto populate when the month and year is entered.
thanks for suggestions in advance.

Without context, it's not clear what you need. Do you want the user to enter the data in dialog boxes or enter the data into two cells? What format will the user be expected to enter the dates in? For example, should January be entered as "Jan", "January", "1" etc.? You probably just need to have 31 formulas set up that reference the input cells, but you need to specify exactly how that input is handled first.
EDIT:
That was meant to be a comment, not an answer, so here is my actual answer:
In cell A1, set up a data validation rule. The rule should be a list with the source given as "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec" or the longer form if you prefer. Now when you try to edit this cell you have the option of selecting from a drop-down list of months.
If you want to limit the year range as well, you can do something similar in cell B1. Just create comma-separated list of valid years in the source field.
Enter the numbers 1 to 31 in cells A3 to A33 then enter this formula in cell B3:
"=DATEVALUE(A3&"-"&$A$1&"-"&$B$1)"
Autofill/copy that down to B33. The DateValue function takes the calculated string (for example "13-Feb-2017") and converts it to a date which you can then format any way you want. Note that this will produce the error "#VALUE!" if either of the input cells are blank or if the choosen month doesn't have 31 days, but you can modify it to your own needs.

Assume this.
Cell b1 tooks input as month, create a name range rng
cell d1 tooks input as year, create a name range yearsamp
column I and J have this, with a formula in j3.
=IF(MOD(yearsamp,4)=0,29,28)
month days
1 31
2 29
3 31
4 30
5 31
6 30
7 31
8 31
9 30
10 31
11 30
12 31
name above cell range as monthdays
use this formula in A2 and fill
=IF(VLOOKUP(mnth,monthdays,mnth,FALSE)>=ROW(A2)-1,DATE(yearsamp,mnth,ROW(A1)),"N/A")
This is another option to achieve this
You can use this formula also.set up as said above.
on first field for 1st date enter this on A2
=DATE(d1,MATCH(b1,I1:I12,0),1)
On A3 write this forula and fill
=IF(ROW(a2)-1<VLOOKUP(mnth,mnthdays,2,FALSE),a2+1,"")
As you have 31 cells with formula it return errors when the month day count are less than 31 but this formula show those as blank without errors.

Related

Is there a way to calculate a ratio using SUMIFs?

I am trying to get cell I13 on sheet MONTHLY STATS - SPREADS to populate a 0 if there have been no L's to count between the dates of 1 Oct 21 and 31 Oct 21 on sheet SPREADS LOG.
But I only want this 0 to populate if there is data present in cell H13. If there is no data in H13I would like I13 to be blank. (note I cannot use a number format to hide these 0's in cell I13 as I am trying to average the complete I column )
Whilst it is doing this cell I13 must also be able to run the COUNTIFS & SUM formulas shown below.
This is the current formula in cell I13 :
=IF(SUM(COUNTIFS('SPREADS LOG'!P:P,{"L"},'SPREADS LOG'!R:R,">="&DATE(2021,10,1),'SPREADS LOG'!R:R,"<="&DATE(2021,10,31)))=0,"",SUM(COUNTIFS('SPREADS LOG'!P:P,{"L"},'SPREADS LOG'!R:R,">="&DATE(2021,10,1),'SPREADS LOG'!R:R,"<="&DATE(2021,10,31))))
If someone could tweak this formula, that would be great.

In Excel how to count between date1 and date2 that have cells in row that contain text?

I need to choose cells in one column that are between two dates, and then based on the rows that contain those dates, choose cells in another row that also contains content.
I didn't use ISBLANK because it counts a formula yet an empty cell as a not-blank. Instead check if there is content by "*".
Here is what I came up with, but instead of returning the number of cells, instead this returns TRUE (which obviously isn't what I want).
In the formula below I am assuming:
C:C is the whole column containing DATES.
E:E is the whole column containing CONTENT.
The date range in this case is January 1, 2018 to January 31, 2018.
"*" means is there is content in the cell
=IF(AND(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&"2018-1-31"),COUNTIF(E:E,"*"))=0,"",AND(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&"2018-1-31"),COUNTIF(E:E,"*")))
My goal is to:
count the numbers of the cells in column E that are between the dates in column C
if the whole formula is 0, then return a blank.
See this picture of a sample excel sheet to make my intent clear:
How can I get my formula working so it does as needed?
SOLUTION
Hi all, so thanks to #girlvsdata, we have a working solution. I had to do a couple edits to her code to work for my uses, but her formula overall works perfect. Here is the solution:
To choose all cells in column E that are not blank, in between the date range of all of January (unknown end date) based on the adjacent C column if that is your date column, then the solution is:
=IF(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&EOMONTH("2018-1-1",0),E:E,"*")=0,"",COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&EOMONTH("2018-1-1",0),E:E,"*"))
Note that "2018-1-1" is January 1 2018, and EOMONTH("2018-1-1",0) is the last valid day of January in the year 2018 (in this case, 31, but if it is different another year (e.g. for February this works for leap years too) then it will be that last day). Also it eliminates the need to calculate which is the last day or every month, as well as months that have changing end dates dependent on the year (e.g. Feb). This is important to eliminate a margin of error.
The only thing you have to do to change the month is only change e.g. -1- (Jan) to -2- for Feb, or change the year for other years. With this formula you can ignore the day part.
If the answer is 0 (no cells have any content in between the range), then the cell is blank instead of 0. (GOod for when you want to create a sheet checking future dates for future reference when more rows are added to the sheet.
It also works across different sheets, just use, say your other sheet is called "Tracker" then use Tracker!C:C and Tracker!E:E. Hope it helps!
Thank you all! :D
(Please note: My local date format is day, then month)
With the data laid out as in your example above:
A B
1 Dates |Content
------------+-------
2 1/01/2018 |
3 2/01/2018 |123456
4 3/01/2018 |
5 4/01/2018 |12398
6 5/01/2018 |484
7 6/01/2018 |1538
8 7/01/2018 |
9 8/01/2018 |
10 9/01/2018 |
11 10/01/2018 |14648
12 11/01/2018 |
13 12/01/2018 |145615
14 13/01/2018 |
And with the date range in cells D2 and E2:
Date Start Date End
2/01/2018 7/01/2018
This formula returns the count:
=COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0")
This will depend on whether your numbers in Column B are formatted as text or number. If they are formatted as numbers, the above formula will work. If they are formatted as text, replace the last section ">0" with "*".
This formula adds the conditional part of your question:
=IF(COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0")=0,"",COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0"))
(If the formula returns 0, show blank)

excel - drop down list with condition

Maybe the title of the question is wrong, but I'll try to explain what I'm looking for. I have in cell A1 a drop down list to select months (from 1-12). Is it possible to automatically fill the rest of the A column with hourly data for the whole selected month. For example if it's selected "3" in A column'd be:
Time
1.3.2018 1:00:00
1.3.2018 2:00:00
1.3.2018 3:00:00
...
31.3.2018 22:00:00
31.3.2018 23:00:00
1.4.2018 0:00:00
Maybe, something like second drop down list.
Or maybe, it can be done with substitute, but then some months have 31 days, some 30, and february 28, and there is a problem with daylight saving time. In 3rd month, there's one day where I need to have 23 hours (jump from 02:00 to 04:00), and in 10th month one day with 25 hours (02:00, 02:00, 03:00).
In cell A2 enter the following formula:
=DATE(2018,A1,1)
Then custom format the cell with type:
d.m.yyyy hh:mm:ss
In Cell A3 enter the following formula:
=A2+1/24
And change the cell format as above, then drag the cell down to autofill until you have the full month.
There would be multiple ways, but one way is to first determine number of rows required (for March it would be 31 * 24 = 744), set first row using DATE function and then keep adding 1 hour until the desired row number is reached.
Calculate number of rows required in A2: =DAY(EOMONTH(A3,0))*24+ROW()
in A3 enter =DATE(YEAR(TODAY()),A1,1)
in A4 enter =IF(ROW()<=$A$2,A3+1/24,"") and drag down till about 800.
This will make it dynamic for number of days in month

Dynamic starting point of OFFSET and SUM formula

I have the following Excel spreadsheet:
A B C D E F G
1 Year 2015 2016 2017 2018 2019 2020
2 Revenue 5.000 4.000 6.000
3 Years to go back: 2
4 Sum of Periods: 10.000
In Row 1 you can find the years 2015 til 2020 and in Row 2 the corresponding revenue of each year.
In Cell C3 the user should input the number of years to go back and sum up the revenues. For example if the user puts in a 2 Excel goes back 2 years and sums up the revenue of 2017 and 2016 which is 10.000 in the case above. For this I used the following formula:
=SUM(OFFSET($E$2,0,-C3):$E$2)
This formula and the described calculation above work perfectly so far.
However, in 2018 I will have to adjust the starting point of Cell $E$2 in the formula above to Cell $F$2. Ohterwise the year 2018 will be excluded from the calculation.
=SUM(OFFSET($F$2,0,-C3):$F$2)
My question is now how can I avoid this permanent re-adjustment every year?
--> I think the solution should be a formula that identifies the first "non empty" cell within in a Row and then starts counting back the years from this cell. Somehow a combination of the SUM, OFFSET, ROW & COLUMN formula.
You may use this formula:
=SUM(INDIRECT("R2C" & (MATCH(YEAR(TODAY()),$1:$1,0) - $C$3 + 1) & ":R2C" & MATCH(YEAR(TODAY()),$1:$1,0), FALSE))
But be aware I'm assume the current year - $C$3 is within your data range.
Brief explain:
YEAR(TODAY()) - it will return the year of current date, then you don't need to re-adjust every year
MATCH(lookup_value, lookup_array, match_type) - it will find the value matched in first row, and return the index of cell
INDIRECT() - Form the result of match to a R1C1 notation, and convert the text to excel range
A simpler formula could be to use the 4th parameter of OFFSET to set the width and to calculate the starting point of the OFFSET using YEAR(TODAY()0-2016
=SUM(OFFSET($B$2,0,YEAR(TODAY())-$C$1,1,$B$3))
NON VOLATILE OPTION
Well non volatile if it were not for the TODAY() function. Replace TODAY() with a cell containing the starting year as a date. or replace Year(Today()) with a cell reference just containing the year (integer) and then it will be a non volatile option.
=SUM(INDEX($1:$1,MATCH(YEAR(TODAY()),$1:$1,0)):INDEX($1:$1,MATCH(YEAR(TODAY()),$1:$1,0)-($C$3-1))
Volatile functions recalculate every time something on the spreadsheet changes.
Non volatile functions only recalculate when something affecting them changes.
The index function returns the cell address with in the range its looking. for a 2D range you need to give row and column reference. For a 1D range, you only need to give find the position within the range.
Match finds a value within a given range.

defining variables in excel formulas?

i have a simple table data like:
date | Jenna | Tom | Robin
01/01/12 2 5 8
02/01/12 3 4 7
(date columns starts from the first day of the year and goes all the way down to he next year.)
I have a formula getting the min. and max. values (for example for Jenna) for the month January.
I have to change the row numbers every month to get the right result.
Is it possible for me to define variables in two cells and use them in that formula without using VBA.
For example;
I will put two values in H1 and H2 cells, which are 28 and 58 respectively. And i will define E1 as start and E2 as end. And write down this formula:
=min(Cstart:Cend)
=max(Cstart:Cend)
=average(Cstart:Cend)
The first formula means to get the min value between the C28 and C58.
That way i will not have to change every formula manually on the page. I will just change the values of 2 cells and that will be enough.
I hope, I have explained.
Sure. You have to use the INDIRECT() function. INDIRECT transforms a string to a range reference.
=MIN(INDIRECT("C" & $H$1 &":C" & $H$2))

Resources