+ Reply to Thread
Results 1 to 4 of 4

format date list box

Hybrid View

  1. #1
    Registered User
    Join Date
    07-30-2009
    Location
    melbourne, AUS
    MS-Off Ver
    Excel 2003
    Posts
    33

    format date list box

    how do i format a list box to read SAT-25-MAR-09 instead of the defult 3/25/09 the list box has 14 columns, the second column is the column with the date in it. below is the code im using to poulate the list
    the date is in column b on sheet.

    Sub LoadlistBox()
        
        Dim lbtarget As MSForms.ListBox
        Dim rngsource As Range
        
    
        Set rngsource = Worksheets("Scedtest").Range("A2:N50")
        'Fill the listbox
        Set lbtarget = Me.ListBox1
        
        With lbtarget
            .ColumnCount = 14
            .ColumnWidths = "60;80;130;60;30;100;150;250;1;1;1;1;1;1"
            .List = rngsource.Cells.Value
        End With

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: format date list box

    You need to format the date and update the list entry
    Assumes date is in column B of range.

        Dim lngIndex As Long
        
        With Me.ListBox1
            .ColumnCount = 14
            .ColumnWidths = "60;80;130;60;30;100;150;250;1;1;1;1;1;1"
            .List = Range("A2:N12").Value
            For lngIndex = 0 To .ListCount - 1
                .List(lngIndex, 1) = UCase(Format(CDate(.List(lngIndex, 1)), "ddd-dd-mmm-yy"))
            Next
        End With
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    07-30-2009
    Location
    melbourne, AUS
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: format date list box

    thanks andy

    The provided code worked, with 1 little hiccup if there is a blank row it adds
    the date to it.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: format date list box

    You could check the length of the text before applying the formatting.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1