how to put listbox data in date order

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,227
Office Version
  1. 2010
Platform
  1. Windows
Hi good morning, please can you help me, i have a userform with several textboxes where you can add data, the data is sent to sheet1 and the data shows in my listbox1 and listbox2 (which are linked together by this code ListBox2.ListIndex = ListBox1.ListIndex and ListBox1.ListIndex = ListBox2.ListIndex in each listbox) in the userform where i can view it. When i am adding data in my listboxes column A of listbox1 is the date, and once i click the add button it gets added, but when it adds in my list box it gets added to the bottom of the listbox. i would like it to add the newest date at the top and show the oldest date at the bottom. Please can you help me with this, i have attached the link to my userform so you can see what i mean.

running stats 2.xlsm stats 2.xlsm?dl=0
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi,
How about instead of adding the record to the next blank row in worksheet - insert a new row in row 2 & place the new record there?
Then when you refresh your listboxes, record should be in required order.

Dave
 
Upvote 0
Hi Dave how will i do that please? do i just insert a blank row in sheet1?
 
Upvote 0
try replacing this line

VBA Code:
'find first row in Sheet1
irow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

with this

VBA Code:
 ws.Range("A2").EntireRow.Insert , CopyOrigin:=xlFormatFromRightOrBelow
irow = 2

and see if this will do what you want

Dave
 
Upvote 0
thanks Dave i will try that do i also need to move my data out of line to in sheet1 for it to work?
 
Upvote 0
thanks Dave i will try that do i also need to move my data out of line to in sheet1 for it to work?

All change should do is place a new record in Row 2 as opposed to the next blank row at bottom of your data. No other change should be needed.

As always, make a back-up before testing new code

Dave
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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