Re: How To Refresh UserForm ListBox
Quote from cytop;747086
I'm sorry, maybe I'm having a bad day but I don;t understand what you mean by "...sort the listbox in a way that date matches the FName"
I'm also sorry provided I couldn't express my issue well as for a couple of hours I see everything like sub, private sub, dim, private declare etc.

What I've try to meant was: (please do apologize my dumb ass explaining style)
1. My filename format in relevant folders are: yymmdd_PackageNr_Submittal_Log.xlsm (i.e. 150527_MP02_Submittal_Log.xlsm)
2. File filename is read, put it in a listbox (lbFileList) row and the name is divided into 2 columns: Date & Filename (I have little bit changed your code like below)
While fName <> ""
If InStr(fName, logType) > 0 Then
k = k + 1
ReDim Preserve fileList(1 To k)
fileList(k) = fName
With ufBackupList.lbFileList
.AddItem fileList(k)
'// Formatted the date as needed
.List(.ListCount - 1, 0) = Format(FileDateTime(fPath & fName), "dd-mm-yy")
.List(.ListCount - 1, 1) = Replace(Mid(fName, 8, 18), "_", " ")
End With
End If
'get next filename
fName = Dir()
Wend
Display More
3. When the user chooses a backup file and double click, filename can be read appropriately
MsgBox fileList(lbFileList.ListIndex + 2)
No problem till here...
But I want lbFileList listbox to be sorted in descending order (both columns), but "...sort the listbox in a way that date matches the FName" meaning:
(selected item; theoretically) listbox column0 value ("27-05-15") + listbox column1 value ("MP02 Submittal Log") should point out "150527_MP02_Submittal_Log.xlsm"
What the problem might be here is; there are some files where (manually given during saveas) "yymmdd" part of the filename might not match with the FileDateTime function, because there we read the actual saved date&time of the file. I mean; today (27/05/2015) I save the file but the log belongs to yesterday's data, so I saveas the file 150526_MP02_Submittal_Log.xlsm.
To overcome this problem, I had tried to get the "date" values with below coding:
Format(CDate(Mid(fName, 5, 2) & "/" & Mid(fName, 3, 2) & "/" & Mid(fName, 1, 2)), "dd-mm-yy")
Sorry for too long explanation for a simple question, but I just wanted to reflect my idea very clearly.
Thnx for your efforts pal...