sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,422
- Office Version
- 2016
- Platform
- Windows
I have a strange behaviour occurring whilst trying to load a Listbox on a Userform.
I have the following code which populates the Listbox with data dependant on the value of column E:
If I load the userform from within the VBE the dates are formatted correctly, (dd/mm/yyyy hh:mm - these are in column C on the sheet). However, if I load the userform from a custom ribbon command which simply says "Userform1.show" then it loads the dates as "mm/dd/yyyy hh:mm:ss".
Does anyone know why this may be the case?
I have the following code which populates the Listbox with data dependant on the value of column E:
Code:
Private Sub UserForm_Initialize()Dim Rng As Range, Dn As Range, c As Long, Ray()
Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
For Each Dn In Rng
If Range("E" & Dn.Row) = vbNullString Then
c = c + 1
ReDim Preserve Ray(1 To 4, 1 To c)
Ray(1, c) = Dn.Value
Ray(2, c) = Dn.Offset(, 1).Value
Ray(3, c) = Dn.Offset(, 2).Value
Ray(4, c) = Dn.Offset(, 3).Value
End If
Next Dn
With Me.ListBox1
.Clear
.ColumnCount = 4
.ColumnWidths = "60;120,75,50"
.List = Application.Transpose(Ray)
End With
End Sub
If I load the userform from within the VBE the dates are formatted correctly, (dd/mm/yyyy hh:mm - these are in column C on the sheet). However, if I load the userform from a custom ribbon command which simply says "Userform1.show" then it loads the dates as "mm/dd/yyyy hh:mm:ss".
Does anyone know why this may be the case?