+ Reply to Thread
Results 1 to 9 of 9

date formatting in userform

Hybrid View

  1. #1
    Registered User
    Join Date
    01-12-2012
    Location
    Staffordshire
    MS-Off Ver
    Excel 2010
    Posts
    38

    date formatting in userform

    i have a number of textboxes where i input dates or not but i would like dates to be DD/MM/YY not MM/DD/YY i dont fill all boxes so sometimes have blanks and when i fill in boxes a may delete date if that person no longer have
    any help would be good

    Private Sub save_Click()
    
    Dim iRow As Long
    Dim ws As Worksheet
    Sheets("Data").Unprotect password:=""
    Set ws = Worksheets("Data")
    
    iRow = Range(Me.TextBox7).Row
    
      'check for a name
    If Trim(Me.TextBox1.Value) = "" Then
      Me.TextBox1.SetFocus
      MsgBox "Please enter a first name"
      Exit Sub
      Else: Me.TextBox1.Value = Me.TextBox1.Value
    End If
    
    'copy the data to the database
    ws.Cells(iRow, 1).Value = Me.TextBox1.Value
    ws.Cells(iRow, 2).Value = Me.TextBox2.Value
    ws.Cells(iRow, 3).Value = Me.Num1.Value
    ws.Cells(iRow, 4).Value = Me.TextBox8.Text
    ws.Cells(iRow, 5).Value = Me.Num2.Value
    ws.Cells(iRow, 6).Value = (Me.TextBox9.Text)
    ws.Cells(iRow, 7).Value = Me.Num3.Value
    ws.Cells(iRow, 8).Value = (Me.TextBox10.Text)
    ws.Cells(iRow, 9).Value = Me.Num4.Value
    ws.Cells(iRow, 10).Value = (Me.TextBox11.Text)
    ws.Cells(iRow, 11).Value = Me.Num5.Value
    ws.Cells(iRow, 12).Value = (Me.TextBox12.Text)
    ws.Cells(iRow, 13).Value = Me.Num6.Value
    ws.Cells(iRow, 14).Value = (Me.TextBox13.Text)
    ws.Cells(iRow, 15).Value = Me.Num7.Value
    ws.Cells(iRow, 16).Value = (Me.TextBox14.Text)
    ws.Cells(iRow, 17).Value = Me.Num8.Value
    ws.Cells(iRow, 18).Value = (Me.TextBox15.Text)
    ws.Cells(iRow, 19).Value = Me.Num9.Value
    ws.Cells(iRow, 20).Value = (Me.TextBox16.Text)
    ws.Cells(iRow, 21).Value = Me.Num10.Value
    ws.Cells(iRow, 22).Value = (Me.TextBox17.Value)
    ws.Cells(iRow, 23).Value = Me.Num11.Value
    ws.Cells(iRow, 24).Value = (Me.TextBox18.Value)
    ws.Cells(iRow, 25).Value = Me.Num12.Value
    ws.Cells(iRow, 26).Value = (Me.TextBox19.Value)
    ws.Cells(iRow, 27).Value = Me.Num13.Value
    ws.Cells(iRow, 28).Value = (Me.TextBox20.Value)
    ws.Cells(iRow, 29).Value = Me.Num14.Value
    ws.Cells(iRow, 30).Value = (Me.TextBox21.Value)
    ws.Cells(iRow, 31).Value = Me.Num15.Value
    ws.Cells(iRow, 32).Value = (Me.TextBox22.Value)
    ws.Cells(iRow, 33).Value = Me.Num16.Value
    ws.Cells(iRow, 34).Value = (Me.TextBox23.Value)
    ws.Cells(iRow, 35).Value = Me.Num17.Value
    ws.Cells(iRow, 36).Value = (Me.TextBox24.Value)
    ws.Cells(iRow, 37).Value = Me.Num18.Value
    ws.Cells(iRow, 38).Value = (Me.TextBox25.Value)
        
    
    'ws.Cells(iRow, 11).Value = Me.TextBox8.Value
    
    
    
     Sheets("Data").Protect password:=""
     Me.hide
     Unload Me
        UserForm3.Show
    
    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: date formatting in userform

    Try converting the 'text' dates into 'real' dates using CDate or DateValue.

    For example if TextBox9 contained a date.
    ws.Cells(iRow, 6).Value = CDate(Me.TextBox9.Text)
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-12-2012
    Location
    Staffordshire
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: date formatting in userform

    sorry i cant get it working if i use Cdate it works if i fill in the box but if that box is blank it showa error, its showing it right on the userform but not in excel sheet i have formatted the excel sheet to uk DD/MM/YY
    this is what i have done to the code it really doing my head in i did try and upload file but did not work

    ws.Cells(iRow, 1).Value = Me.TextBox1.Value
    ws.Cells(iRow, 2).Value = Me.TextBox2.Value
    ws.Cells(iRow, 3).Value = Me.Num1.Value
    ws.Cells(iRow, 4).Value = Format(Me.TextBox8.Value, "DD/MM/YY")
    ws.Cells(iRow, 5).Value = Me.Num2.Value
    ws.Cells(iRow, 6).Value = Format(Me.TextBox9.Value, "DD/MM/YY")
    ws.Cells(iRow, 7).Value = Me.Num3.Value
    ws.Cells(iRow, 8).Value = Format(Me.TextBox10.Value, "DD/MM/YY")
    ws.Cells(iRow, 9).Value = Me.Num4.Value
    ws.Cells(iRow, 10).Value = Format(Me.TextBox11.Value, "DD/MM/YY")
    ws.Cells(iRow, 11).Value = Me.Num5.Value
    ws.Cells(iRow, 12).Value = Format(Me.TextBox12.Value, "DD/MM/YY")
    ws.Cells(iRow, 13).Value = Me.Num6.Value
    ws.Cells(iRow, 14).Value = Format(Me.TextBox13.Value, "DD/MM/YY")
    ws.Cells(iRow, 15).Value = Me.Num7.Value
    ws.Cells(iRow, 16).Value = Format(Me.TextBox14.Value, "DD/MM/YY")
    ws.Cells(iRow, 17).Value = Me.Num8.Value
    ws.Cells(iRow, 18).Value = Format(Me.TextBox15.Value, "DD/MM/YY")
    ws.Cells(iRow, 19).Value = Me.Num9.Value
    ws.Cells(iRow, 20).Value = Format(Me.TextBox16.Value, "DD/MM/YY")
    ws.Cells(iRow, 21).Value = Me.Num10.Value
    ws.Cells(iRow, 22).Value = Format(Me.TextBox17.Value, "DD/MM/YY")
    ws.Cells(iRow, 23).Value = Me.Num11.Value
    ws.Cells(iRow, 24).Value = Format(Me.TextBox18.Value, "DD/MM/YY")
    ws.Cells(iRow, 25).Value = Me.Num12.Value
    ws.Cells(iRow, 26).Value = Format(Me.TextBox19.Value, "DD/MM/YY")
    ws.Cells(iRow, 27).Value = Me.Num13.Value
    ws.Cells(iRow, 28).Value = Format(Me.TextBox20.Value, "DD/MM/YY")
    ws.Cells(iRow, 29).Value = Me.Num14.Value
    ws.Cells(iRow, 30).Value = Format(Me.TextBox21.Value, "DD/MM/YY")
    ws.Cells(iRow, 31).Value = Me.Num15.Value
    ws.Cells(iRow, 32).Value = Format(Me.TextBox22.Value, "DD/MM/YY")
    ws.Cells(iRow, 33).Value = Me.Num16.Value
    ws.Cells(iRow, 34).Value = Format(Me.TextBox23.Value, "DD/MM/YY")
    ws.Cells(iRow, 35).Value = Me.Num17.Value
    ws.Cells(iRow, 36).Value = Format(Me.TextBox24.Value, "DD/MM/YY")
    ws.Cells(iRow, 37).Value = Me.Num18.Value
    ws.Cells(iRow, 38).Value = Format(Me.TextBox25.Value, "DD/MM/YY")

  4. #4
    Registered User
    Join Date
    01-12-2012
    Location
    Staffordshire
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: date formatting in userform

    i managed to download file if anybody can have a look at this if you need to login to my system the username is username and password is password
    thanks
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    01-12-2012
    Location
    Staffordshire
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: date formatting in userform

    all codes i am using is from bits off the web so if you can see a better way that would be good thanks

  6. #6
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: date formatting in userform


  7. #7
    Registered User
    Join Date
    01-12-2012
    Location
    Staffordshire
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: date formatting in userform

    can anyone help please? I have inserted an exemple above.
    Thanks

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: date formatting in userform

    I responded in the OzGrid thread.

  9. #9
    Registered User
    Join Date
    01-12-2012
    Location
    Staffordshire
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: date formatting in userform

    thanks Norie that solution did not work

    i would like to thank everyone that helped i have found the solution all i needed to do was change "DD/MM/YY") to "DD/MMM/YYYY") and it works perfect,

+ 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. Formatting a date from userform, then filtering.
    By Ash_ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2014, 01:15 PM
  2. Date picker UserForm to stay always in front of the main UserForm
    By Gabor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-11-2014, 07:31 AM
  3. [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
  4. [SOLVED] Userform TextBox Problem... formatting code clears data instead of formatting
    By michaeljoeyeager in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-26-2012, 11:00 AM
  5. [SOLVED] Userform Date Formatting MM/DD/YYYY
    By Mike in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-09-2010, 12:51 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