list box date i

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,227
Office Version
  1. 2010
Platform
  1. Windows
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
 
thank you so much that works just great, i do appreciate your help. i would be lost without all your help, thank you
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,214,818
Messages
6,121,725
Members
449,049
Latest member
MiguekHeka

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top