Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel to make the days cary over month to month automaticly GARY New Users to Excel 1 April 19th 08 06:05 PM
Number of days in month counted from shortened name of month & yea Tumar Excel Worksheet Functions 6 September 18th 07 03:36 PM
Days per month for calculating storage days Bart Excel Worksheet Functions 3 January 31st 07 06:40 PM
function to fill all days of month to end of month YaHootie Excel Worksheet Functions 10 May 1st 06 06:01 AM
formula for days in month - days left??? Jason[_18_] Excel Programming 3 August 23rd 03 09:58 PM


All times are GMT +1. The time now is 09:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"