+ Reply to Thread
Results 1 to 4 of 4

Getting all days of month from inputbox?

Hybrid View

  1. #1
    Registered User
    Join Date
    11-19-2004
    Posts
    16

    Getting all days of month from inputbox?

    Hi All-
    Does anyone know of a way to get/calculate ALL of the days of the months from a date range entered into an inputbox in which a user may enter any day of a month? In other words, the user enters 9/14/2009 in the first inputbox then 10/8/2012 in the second and code would calculate the number of days as 9/1/2009 - 10/31/2012.

    Here is the current code I'm using that calculates only the exact days:
    Dim DBstarts As Date
    Dim DBends As Date
    
    DBstarts = InputBox("Enter the Date that DB begins:")
    
    DBends = InputBox("Enter the Date in which DB ends:")
    
    daysofDB = -(DBstarts - DBends)
    
    MsgBox daysofDB
    [/SIZE]
    Last edited by FuzzyDove; 08-13-2009 at 10:25 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Getting all days of month from inputbox?

    Use dateDiff
        Dim DBstarts As Date
        Dim DBends As Date
        Dim daysofDB As Long
    
        DBstarts = InputBox("Enter the Date that DB begins:")
    
        DBends = InputBox("Enter the Date in which DB ends:")
    
        daysofDB = DateDiff("d", DBstarts, DBends)
    
        MsgBox daysofDB
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Getting all days of month from inputbox?

    Perhaps:

    Sub example()
    Dim DBstarts As Date, DBends As Date, daysofDB As Long
    DBstarts = Application.InputBox("Enter the Date that DB begins:", "Start Date", Type:=1)
    DBends = Application.InputBox("Enter the Date in which DB ends:", "End Date", Type:=1)
    If DBstarts > 0 And DBends > 0 Then
        daysofDB = (DateAdd("m", 1, DBends) - Day(DBends)) - (DBstarts - Day(DBstarts) + 1)
        MsgBox daysofDB
    End If
    End Sub

  4. #4
    Registered User
    Join Date
    11-19-2004
    Posts
    16

    Re: Getting all days of month from inputbox?

    DonkeyOte - your version works perfectly!! thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1