#1   Report Post  
Jeff
 
Posts: n/a
Default Calendar in VBA

Hello,

Is it possible to design a VBA macro that would return the number of days in
a specific month?
Ex. I'd input a month(December) and the VBA would return (31).
Thanks,

  #2   Report Post  
Jason Morin
 
Posts: n/a
Default

The number of days in a month is affected by the year
(leap year), so with a formula use:

=EOMONTH((A1&"-"&C1)*1,0)-(A1&"-"&C1)*1+1

where A1 holds the month and C1 holds the year (like
2004).

If the formula returns the #NAME? error, install and load
the Analysis ToolPak add-in under Tools Add-Ins.

HTH
Jason
Atlanta, GA


-----Original Message-----
Hello,

Is it possible to design a VBA macro that would return

the number of days in
a specific month?
Ex. I'd input a month(December) and the VBA would return

(31).
Thanks,

.

  #3   Report Post  
Jeff
 
Posts: n/a
Default

Thank you for help.
Is there a way to get the number of Saturdays and Sundays in specific month ?
Ex. I'd input November and Excel would return 8.
Regards,


"Jason Morin" wrote:

The number of days in a month is affected by the year
(leap year), so with a formula use:

=EOMONTH((A1&"-"&C1)*1,0)-(A1&"-"&C1)*1+1

where A1 holds the month and C1 holds the year (like
2004).

If the formula returns the #NAME? error, install and load
the Analysis ToolPak add-in under Tools Add-Ins.

HTH
Jason
Atlanta, GA


-----Original Message-----
Hello,

Is it possible to design a VBA macro that would return

the number of days in
a specific month?
Ex. I'd input a month(December) and the VBA would return

(31).
Thanks,

.


  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

Until Jason comes back...

One way with the real date in A1:

=DAY(EOMONTH(A1,0))-NETWORKDAYS(EOMONTH(A1,-1),EOMONTH(A1,0))


=DAY(EOMONTH(A1,0))
is another way to get the number of days in a month.

=EOMONTH(A1,-1)
is the date of the last day of the previous month.

=EOMONTH(A1,0)
is the date of the last date of the month in A1

=networkdays()
is the number of working days (yech!) between two dates. It ignores Saturday
and Sunday.

If I had "December" in a cell, I'd either type it as a date (12/01/2004,
mm/dd/yyyy) and format it to only show the month.

Or I'd use a formula like Jason's in a helper cell and use that as the reference
in my formula.

=(A1&"-"&C1)*1
(format as date and you'll see it)


Jeff wrote:

Thank you for help.
Is there a way to get the number of Saturdays and Sundays in specific month ?
Ex. I'd input November and Excel would return 8.
Regards,

"Jason Morin" wrote:

The number of days in a month is affected by the year
(leap year), so with a formula use:

=EOMONTH((A1&"-"&C1)*1,0)-(A1&"-"&C1)*1+1

where A1 holds the month and C1 holds the year (like
2004).

If the formula returns the #NAME? error, install and load
the Analysis ToolPak add-in under Tools Add-Ins.

HTH
Jason
Atlanta, GA


-----Original Message-----
Hello,

Is it possible to design a VBA macro that would return

the number of days in
a specific month?
Ex. I'd input a month(December) and the VBA would return

(31).
Thanks,

.



--

Dave Peterson
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
Ploting dates against a calendar and not as a simple events Barb Reinhardt Charts and Charting in Excel 2 January 22nd 05 02:41 AM
Calendar 13 Periods 4 weeks each CHawk@Mcc Excel Discussion (Misc queries) 2 December 10th 04 04:27 PM
Weeks in a Calendar GregR Excel Discussion (Misc queries) 2 December 9th 04 12:55 AM
Fiscal Calendar Eileen Excel Discussion (Misc queries) 1 November 27th 04 09:29 AM
calendar spreadsheet G Graham Excel Discussion (Misc queries) 1 November 26th 04 05:38 PM


All times are GMT +1. The time now is 02:53 PM.

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

About Us

"It's about Microsoft Excel"