Consulting

Results 1 to 6 of 6

Thread: Time in userform listbox

  1. #1
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location

    Time in userform listbox

    If i have a row in a spreadsheet that is formatted hh:mm, how do i get my list box to display it in the same format?

    something similar to below i guessing although the below doesnt work for me

    For i = 3 To LastRow
            If Cells(i, "G").value = "y" Then
                oLB.AddItem Cells(i, "A")
                oLB.List(oLB.ListCount - 1, 1) = Cells(i, "B")
                oLB.List(oLB.ListCount - 1, 2) = Cells(i, "C")
                oLB.List(oLB.ListCount - 1, 3) = Cells(i, "D")
                oLB.List(oLB.ListCount - 1, Format(4, "hh:mm")) = Cells(i, "E")
                oLB.List(oLB.ListCount - 1, 5) = Cells(i, "F")
                oLB.List(oLB.ListCount - 1, 6) = i
            End If

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Use the Text property to get the value in a cell as it is formatted.
    oLB.List(oLB.ListCount - 1, 4, "hh:mm") = Cells(i, "E").Text

  3. #3
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    didnt work for me, just got a blank column

  4. #4
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    How about this?
    oLB.List(oLB.ListCount - 1, 4) = Cells(i, "E").Text
    I'm assuming the time you want is in column E.

  5. #5
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Norie, now that worked great

    thanks again for your help

    Cant believe how much im learning in here with the help of you all, it is very appreciated

    Gibbo

    Gibbo

  6. #6
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Gibbo

    Glad it worked, I think it was just a typo in the code of my first post.

    Don't know why I forgot to delete the "hh:mm".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •