Results 1 to 8 of 8

Userform - User enters date into Textbox1, want Textbox2 to return a date based on formula

Threaded View

Quasis Userform - User enters date... 01-30-2017, 10:06 AM
DannyJ Re: Userform - User enters... 01-30-2017, 10:19 AM
Arkadi Re: Userform - User enters... 01-30-2017, 11:05 AM
Quasis Re: Userform - User enters... 01-30-2017, 12:48 PM
Arkadi Re: Userform - User enters... 01-30-2017, 12:54 PM
Winon Re: Userform - User enters... 01-30-2017, 12:59 PM
Arkadi Re: Userform - User enters... 01-30-2017, 01:01 PM
Winon Re: Userform - User enters... 01-30-2017, 01:06 PM
  1. #1
    Registered User
    Join Date
    04-29-2015
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    82

    Userform - User enters date into Textbox1, want Textbox2 to return a date based on formula

    Hi All,

    I'm hoping you may be able to assist.

    I have a userform that when the user enters a date into textbox1, I'd like textbox2 to fill in with a date respective to the date in textbox1. I have this working in a normal excel sheet, but I'd like to remove formulas from the sheet and have them auto calculate in the userform. The formula I'm currently using is =A3+12-WEEKDAY(A3) this will always return the following Thursday of the next week.

    Is anyone able to help?

    Many thanks.

    Kind Regards,
    Quasis

    Solved with:

    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    'I used exit event, AfterUpdate is another option.
    Dim myDays As Integer
    If TextBox1.Value = vbNullString Then Exit Sub 'don't do anything if textbox1 is blank
    
    If IsDate(TextBox1.Value) Then 'check whether textbox1 contains a date
        myDays = 8 - Weekday(TextBox1.Value, vbThursday) 'find the difference in days between today and thursday
        'next line checks if next thursday is this week or next, then adds 7 days if it is this week's thursday
        If Int(((CDate(TextBox1.Value) - DateSerial(Year(CDate(TextBox1.Value)), 1, 0)) + 6) / 7) = Int(((DateAdd("d", myDays, TextBox1.Value) - DateSerial(Year(DateAdd("d", myDays, TextBox1.Value)), 1, 0)) + 6) / 7) Then myDays = myDays + 7
        TextBox2.Value = DateAdd("d", myDays, TextBox1.Value)
    End If
    
    End Sub
    Many thanks to Arkadi.
    Last edited by Quasis; 01-30-2017 at 12:46 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Disable Textbox1 if Textbox2 is populated
    By Sphax in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-25-2015, 11:47 AM
  2. [SOLVED] error if no value in textbox1 or textbox2
    By James__S in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-06-2015, 09:04 AM
  3. [SOLVED] Sort by name Userform.....Textbox1, Textbox2, Textbox3, Textbox4
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2014, 07:53 AM
  4. [SOLVED] Userform Textbox1 = Val(Textbox2.Value) / 2
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-14-2013, 09:37 AM
  5. [SOLVED] Cell Value = TextBox1.Value + TextBox2.Value
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-25-2013, 09:30 AM
  6. [SOLVED] textbox1 * textbox2 = textbox3
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-23-2012, 03:35 PM
  7. [SOLVED] TextBox1 = TextBox2
    By Anto_BT in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2012, 03:34 AM

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