Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Finding Number Of Days in a month

Hi I need to find uot how many days are in a month in VBA
is there a way of doing this if so can someone help me
please TIA
Charles
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Finding Number Of Days in a month

Hi
try
Sub foo()
Dim date_value As Date
date_value = CDate("01.03.2004")
MsgBox Day(CDate(Month(date_value) + 1 & "-" & "1-" &
Year(date_value)) - 1)
End Sub

you may have to adapt the CDate part to your regional date settings


--
Regards
Frank Kabel
Frankfurt, Germany

Charles wrote:
Hi I need to find uot how many days are in a month in VBA
is there a way of doing this if so can someone help me
please TIA
Charles


  #3   Report Post  
Posted to microsoft.public.excel.programming
LEB LEB is offline
external usenet poster
 
Posts: 3
Default Finding Number Of Days in a month


-----Original Message-----
Hi I need to find uot how many days are in a month in

VBA
is there a way of doing this if so can someone help me
please TIA
Charles
.

This probably isn't the best way, but you could run a
Do...Until loop. use two variables as counters. Use the
first counter variable, initialized to the value 1, and
run the loop until the variable is greater than 31 days.
Create a text date value from each value of the first
counter variable [Ex: CurrDate=Month(date)&"/" & counter
& "/" & Year(date)]. Then test to see if the date is
valid, using an If...Then test and the IsDate function
[Ex: if IsDate(CurrDate) then...

If the date is valid, increment the second counter to
keep track of the number of days in the month, increment
the first counter to its next value, and repeat the loop.
if the date isn't valid, exit the loop, and the number of
days in the month will be the value of the second
counter.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Finding Number Of Days in a month

Hi Charles

This is how I'd do it:

Function DaysInMonth(Dt As Date) As Long
DaysInMonth = Day(DateSerial(Year(Dt), _
Month(Dt) + 1, 0))
End Function

Sub test()
Dim L As Long, Dt As Date
For L = 1 To 12
Dt = DateSerial(2004, L, 1)
MsgBox _
Format(Dt, "mmmm yyyy") & " has " & _
DaysInMonth(Dt) & " days"
Next
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Charles" wrote in message
...
Hi I need to find uot how many days are in a month in VBA
is there a way of doing this if so can someone help me
please TIA
Charles



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Finding Number Of Days in a month

Sub test()
Dim dtm As Date, lngDays As Long
dtm = "25-Feb-2004"

lngDays = Day(DateSerial(Year(dtm), Month(dtm) + 1, 0))

MsgBox lngDays
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Charles" wrote in message
...
Hi I need to find uot how many days are in a month in VBA
is there a way of doing this if so can someone help me
please TIA
Charles



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
Number of days in month counted from shortened name of month & yea Tumar Excel Worksheet Functions 6 September 18th 07 03:36 PM
Finding the number of Days in the month? Will Excel Discussion (Misc queries) 1 April 13th 07 09:37 PM
Number of Days in the Month Beth Excel Discussion (Misc queries) 2 March 2nd 06 03:44 PM
How can I add up lookups? Finding days in a week of a month Michael at Thin Air Excel Discussion (Misc queries) 5 January 29th 06 06:55 PM
number of days in a month Ryan Proudfit Excel Worksheet Functions 8 April 7th 05 08:02 PM


All times are GMT +1. The time now is 02:20 AM.

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"