+ Reply to Thread
Results 1 to 9 of 9

Date in userform textbox

  1. #1
    Registered User
    Join Date
    08-21-2013
    Location
    Birmingham
    MS-Off Ver
    Excel 2003
    Posts
    25

    Date in userform textbox

    Hi there

    I have a query that I am slightly puzzled by (I know this will seem like a day 1 beginners question for you).
    I am using a userform with 4 textboxes to extract information from a worksheet using information in textbox 1. 1 box looks up a date but returns the date in numerical format (42682) instead of dd/mm/yyyy. The date is formatted correctly in the worksheet, but will not extract correctly to the userform. The code I'm using is:

    Please Login or Register  to view this content.
    I tried this code after the With Me command -

    copy to clipboard
    Please Login or Register  to view this content.
    but this returns a fault on this code line

  2. #2
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: Date in userform textbox

    .DateTextBox = Format(Application.WorksheetFunction.VLookup(Me.KSTextBox, Sheet1.Range("D2:K1000"), 4, 0), "dd/mm/yyyy")
    Frob first, tweak later

  3. #3
    Registered User
    Join Date
    08-21-2013
    Location
    Birmingham
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Date in userform textbox

    Brilliant
    Works a treat. Thanks very much Neil_

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Date in userform textbox

    One word of advice though since you perform 3 times a vlookup to fill 3 TextBoxes.
    Do 1 search to find value in 4th column then fill all TextBoxes in one go.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Registered User
    Join Date
    08-21-2013
    Location
    Birmingham
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Date in userform textbox

    Hi have tried updating my code to the below, but, it will still not write to worksheet when I click the OK button. Have I entered a line of code wrong somewhere?

    Please Login or Register  to view this content.

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Date in userform textbox

    Yes, you did.
    This part belongs to your OK button.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-21-2013
    Location
    Birmingham
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Date in userform textbox

    Whoops,

    Sorry, I forgot about coding the OK button. Only issue I'm getting is with the date input (going in as American dates) Cells are formatted to dd/mm/yyyy.
    I have tried to amend the code to:

    Please Login or Register  to view this content.
    This returns a syntax error. I then tried

    Please Login or Register  to view this content.
    No formatting code I try seems to work

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Date in userform textbox

    Like this.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-21-2013
    Location
    Birmingham
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Date in userform textbox

    Sorry

    Don't think I explained that well. Tried the code you have given me previously.
    The issue is when I input the data to the worksheet from the userform it converts to American formatting mm/dd/yyyy. I need it to input as dd/mm/yyyy

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to get date clicked on monthview to my textbox on userform?
    By excelkann in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-11-2016, 04:32 PM
  2. [SOLVED] Excel 2010 - Userform - display date from textbox in a label or textbox in 'ddd' format
    By theshybutterfly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2015, 10:54 PM
  3. [SOLVED] Userform Textbox Date Format
    By saban1974 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-12-2014, 10:52 AM
  4. [SOLVED] Excel 2007, Userform Textbox Date Format and Calendar Control Userform
    By riffology in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-03-2014, 06:18 PM
  5. [SOLVED] Userform Textbox Date - Subtract Weekend
    By Nu2Java in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-12-2012, 05:14 PM
  6. Date Format for textbox in userform
    By processchip in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-08-2011, 06:42 AM
  7. Entering a date into a userform textbox
    By jerseyguy1996 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-01-2010, 12:28 PM

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