list box date i

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,081
hi my listbox data from the textbox1 the date is in american format how do i force it to show dd/mm/yy? the code below is for my textbox1 and the code below that is for my listbox1 hope you can help please?

VBA Code:
Private Sub TextBox1_Change()


    Dim ascii   As Integer
    Dim d       As Integer
    Dim m       As Integer
    Dim n       As Integer
    
        n = Len(TextBox1.Value)
        
        If n = 0 Then Exit Sub
        
            ascii = Asc(Right(TextBox1.Value, 1))
            
            ' Validate the day is 2 digits from 01 to 31.
            If n = 2 And ascii <> 47 And CharCode <> 8 Then
                d = CInt(Left(TextBox1.Value, 2))
                If d < 1 Or d > 31 Then
                    MsgBox "Invalid day number " & d & vbLf & "Days are from 01 to 31."
                    TextBox1.Value = ""
                    Exit Sub
                End If
            End If
            
            ' Validate the month is 2 digits from 01 to 12.
            If n = 5 And ascii <> 47 And CharCode <> 8 Then
                m = CInt(Mid(TextBox1.Value, 4, 2))
                If m < 1 Or m > 12 Then
                    MsgBox "Invalid month number " & m & vbLf & "Months are from 01 to 12."
                    TextBox1.Value = Left(TextBox1.Value, 3)
                End If
            End If
                      
End Sub

Code:
Private Sub ListBox1_AfterUpdate()
ListBox2.ListIndex = ListBox1.ListIndex

   Me.TextBox1.Value = Me.ListBox1.Column(0)
    Me.TextBox2.Value = Me.ListBox1.Column(1)
     Me.TextBox3.Value = Me.ListBox1.Column(2)
     Me.TextBox4.Value = Me.ListBox1.Column(3)
     Me.TextBox5.Value = Me.ListBox1.Column(4)
     Me.TextBox6.Value = Me.ListBox1.Column(5)
     Me.TextBox7.Value = Me.ListBox1.Column(6)
     Me.TextBox10.Value = Me.ListBox2.Column(0)
     Me.TextBox11.Value = Me.ListBox2.Column(1)
     Me.TextBox12.Value = Me.ListBox2.Column(2)
     Me.TextBox13.Value = Me.ListBox2.Column(3)
     Me.TextBox14.Value = Me.ListBox2.Column(4)
     Me.TextBox15.Value = Me.ListBox2.Column(5)
     Me.TextBox16.Value = Me.ListBox2.Column(6)
     Me.TextBox17.Value = Me.ListBox2.Column(7)
     Me.TextBox18.Value = Me.ListBox2.Column(8)
     Me.TextBox19.Value = Me.ListBox2.Column(9)
 End Sub
 

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,081
thank you so much that works just great, i do appreciate your help. i would be lost without all your help, thank you
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

NoSparks

Well-known Member
Joined
Mar 15, 2013
Messages
1,008
Office Version
  1. 2010
Platform
  1. Windows
you're welcome and thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,114,337
Messages
5,547,355
Members
410,785
Latest member
phillippaige
Top