Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50139

Displaying date and time format in Listbox

$
0
0
Hi,

The code bellow displays in my Listbox, 2 columns with the date and time from a variable range.


Code:

c = ActiveCell.Column

Days = WorksheetFunction.CountA(Sheet20.Range(Sheet20.Cells(6, c), Sheet20.Cells(65536, c)))

If Days = 0 Or Days = 1 Then
  Rng = Sheet20.Range(Sheet20.Cells(6, c), Sheet20.Cells(7, c + 1)).Cells
  Set lb = Me.L1
  With lb
    .ColumnCount = 2
    .ColumnWidths = "50;50"
    .List = Rng
  End With
Else
  Rng = Sheet20.Range(Sheet20.Cells(6, c), Sheet20.Cells(5 + Days, c + 1)).Cells
  Set lb = Me.L1
  With lb
    .ColumnCount = 2
    .ColumnWidths = "50;50"
    .List = Rng
  End With
End If


Everything code runs ok, the only thing is that the values displayed in my listbox does not have the correct format. The date appears as "mm/dd/yyy" and the time as a number instead of "hh:mm".

Does someone know how to display it properly?

Any help would be much appreciated. Thanks!

Kind regards,

Viewing all articles
Browse latest Browse all 50139

Trending Articles