+ Reply to Thread
Results 1 to 3 of 3

Insert a date from a userform

  1. #1
    Registered User
    Join Date
    06-13-2006
    Posts
    76

    Question Insert a date from a userform

    Hi,

    I have a userform with 2 textboxes. In textbox1 a "from" date should be entered by the user and in textbox2 a "to" date should be entered.
    When I click commandbutton1 (=OK) the "from date should be inserted in cell B10 and all the dates between the "from" and the "to" date should be inserted in the cells below.
    I only don't know how to do this. Can someone help me? Thanks in advance!

  2. #2
    ChasAA
    Guest

    RE: Insert a date from a userform

    Hello,
    Don't know if you want the "to" date to be listed below B10, if you dont
    then reduce the for...next loop by 1 ie (to days-1)

    [Code Starts]

    Private Sub CommandButton1_Click()
    Dim startDate As Date
    Dim endDate As Date
    Dim off As Integer
    Dim days As Integer
    Dim counter As Integer

    startDate = TextBox1.Value
    endDate = TextBox2.Value
    days = DateDiff("d", startDate, endDate)
    Range("B10").Select
    off = 0
    For counter = 0 To days ' change to days-1 if you dont want "to" date
    Selection.Offset(off, 0) = startDate + off
    off = off + 1
    Next
    End Sub
    [Code Ends]

    Happy Coding

    ChasAA

    "leonidas" wrote:

    >
    > Hi,
    >
    > I have a userform with 2 textboxes. In textbox1 a "from" date should be
    > entered by the user and in textbox2 a "to" date should be entered.
    > When I click commandbutton1 (=OK) the "from date should be inserted in
    > cell B10 and all the dates between the "from" and the "to" date should
    > be inserted in the cells below.
    > I only don't know how to do this. Can someone help me? Thanks in
    > advance!
    >
    >
    > --
    > leonidas
    > ------------------------------------------------------------------------
    > leonidas's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=35375
    > View this thread: http://www.excelforum.com/showthread.php?threadid=565510
    >
    >


  3. #3
    Bob Phillips
    Guest

    Re: Insert a date from a userform


    With Worksheets("Sheet1").Range("B10")
    .Value = CDate(TextBox1.Text)
    .AutoFill .Resize(CDate(TextBox2.Text) - CDate(TextBox1.Text) + 1)
    End With


    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "leonidas" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi,
    >
    > I have a userform with 2 textboxes. In textbox1 a "from" date should be
    > entered by the user and in textbox2 a "to" date should be entered.
    > When I click commandbutton1 (=OK) the "from date should be inserted in
    > cell B10 and all the dates between the "from" and the "to" date should
    > be inserted in the cells below.
    > I only don't know how to do this. Can someone help me? Thanks in
    > advance!
    >
    >
    > --
    > leonidas
    > ------------------------------------------------------------------------
    > leonidas's Profile:

    http://www.excelforum.com/member.php...o&userid=35375
    > View this thread: http://www.excelforum.com/showthread...hreadid=565510
    >




+ 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