Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Days in a Month
for the date in cell b6:
=DAY(DATE(YEAR(B6),MONTH(B6)+1,0)) format for integer "KyWilde" wrote in message ... In VBA for excel, how can I find out how many days are in a specific month for a specific year (these are held in variables)? For example: I have "curr_month" holding the current month and "curr_year" holding the current year as well as "last_month", "last_year", etc. I am trying to get the sum of a category from all the days in a month in a column, but the months I will want will change and the days in these months will change with leap years (februrary), etc. Therefore, instead of hardcoding all the years this will happen, is there a function in VBA that does this sort of thing? Thanks! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Days in a Month
In VBA for excel, how can I find out how many days are in a specific month
for a specific year (these are held in variables)? For example: I have "curr_month" holding the current month and "curr_year" holding the current year as well as "last_month", "last_year", etc. I am trying to get the sum of a category from all the days in a month in a column, but the months I will want will change and the days in these months will change with leap years (februrary), etc. Therefore, instead of hardcoding all the years this will happen, is there a function in VBA that does this sort of thing? Thanks! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Days in a Month
You can write a function like the following, which takes a year
and month as parameters. Function DaysInMonth(Y As Integer, M As Integer) As Integer DaysInMonth = Day(DateSerial(Y, M + 1, 0)) End Function This works because the 0th day of one month is the last day of the previous month. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "KyWilde" wrote in message ... In VBA for excel, how can I find out how many days are in a specific month for a specific year (these are held in variables)? For example: I have "curr_month" holding the current month and "curr_year" holding the current year as well as "last_month", "last_year", etc. I am trying to get the sum of a category from all the days in a month in a column, but the months I will want will change and the days in these months will change with leap years (februrary), etc. Therefore, instead of hardcoding all the years this will happen, is there a function in VBA that does this sort of thing? Thanks! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Days in a Month
Thank you, Chip. This was most helpful!
"Chip Pearson" wrote: You can write a function like the following, which takes a year and month as parameters. Function DaysInMonth(Y As Integer, M As Integer) As Integer DaysInMonth = Day(DateSerial(Y, M + 1, 0)) End Function This works because the 0th day of one month is the last day of the previous month. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "KyWilde" wrote in message ... In VBA for excel, how can I find out how many days are in a specific month for a specific year (these are held in variables)? For example: I have "curr_month" holding the current month and "curr_year" holding the current year as well as "last_month", "last_year", etc. I am trying to get the sum of a category from all the days in a month in a column, but the months I will want will change and the days in these months will change with leap years (februrary), etc. Therefore, instead of hardcoding all the years this will happen, is there a function in VBA that does this sort of thing? Thanks! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
excel to make the days cary over month to month automaticly | New Users to Excel | |||
Number of days in month counted from shortened name of month & yea | Excel Worksheet Functions | |||
Days per month for calculating storage days | Excel Worksheet Functions | |||
function to fill all days of month to end of month | Excel Worksheet Functions | |||
formula for days in month - days left??? | Excel Programming |