Listbox date order

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,731
Office Version
  1. 2007
Platform
  1. Windows
On my worksheet i currently have 2048 rows.
In column G the date is added once the parcel has been delivered BUT until then the word POSTED is shown.
When i open my userform NameForDateEntryBox is populated from all customers which have POSTED shown please see screenshot
As you will see that the still awaiting parcels to be delivered start at the top & go down the list,so old date doing down the list to latest date.

My goal is to reverse this so lastest dates start first & older dates are towards the bottome.

Code shown is what populates the list.
I changed XlUp to XlDown but didnt work so obvioulsy dont understand its use.

Rich (BB code):
    Private Sub populate()
   
        ' clear the combobox
        Me.NameForDateEntryBox.Clear
        ' declare variables
        Dim i As Long, lRow As Long, ws As Worksheet
        ' set ws to the desired sheet
        Set ws = Application.Worksheets("POSTAGE")
        ' determine the last row of that desired sheet
        lRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
       
        ' populate the combobox by looping down the rows of ws
        With Me.NameForDateEntryBox
            For i = 8 To lRow
                'determine if this customer should be added to combobox list
                If UCase(ws.Cells(i, 7).Value) = "POSTED" Then
                    .AddItem Cells(i, 2)    'adds the customer name to combobox first column
                    .List(.ListCount - 1, 1) = Cells(i, 1) 'add the date to second column of line just added
                    .List(.ListCount - 1, 2) = Cells(i, 3) 'add the item to third column of line just added
                End If
            Next i
        End With
   
    End Sub
 

Attachments

  • EaseUS_2023_10_13_12_49_19.jpg
    EaseUS_2023_10_13_12_49_19.jpg
    70.9 KB · Views: 6

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Haven't tested. Can you try:
VBA Code:
    Private Sub populate()
    
        ' clear the combobox
        Me.NameForDateEntryBox.Clear
        ' declare variables
        Dim i As Long, lRow As Long, ws As Worksheet
        ' set ws to the desired sheet
        Set ws = Application.Worksheets("POSTAGE")
        ' determine the last row of that desired sheet
        lRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
        
        ' populate the combobox by looping down the rows of ws
        With Me.NameForDateEntryBox
            For i = lRow To 8 Step -1
                'determine if this customer should be added to combobox list
                If UCase(ws.Cells(i, 7).Value) = "POSTED" Then
                    .AddItem Cells(i, 2)    'adds the customer name to combobox first column
                    .List(.ListCount - 1, 1) = Cells(i, 1) 'add the date to second column of line just added
                    .List(.ListCount - 1, 2) = Cells(i, 3) 'add the item to third column of line just added
                End If
            Next i
        End With
    
    End Sub
 
Upvote 0
Solution
Happy that it did work :)
An easy cheat, I reversed the order 😁
VBA Code:
For i = lRow To 8 Step -1
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,179
Members
452,615
Latest member
bogeys2birdies

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