I have a Listbox form control on an Excel sheet which I want to update automatically when the user moves to the sheet. Items will be added to the list from a range of dates that are held on another sheet (called Tables).
However, I only want to display two dates in the list, and they will be the first two dates in the range it finds that are greater than TODAY'S date.
I'm using a For Next loop to go through the range of dates, and using ListBox1.AddItem to display the 2 dates BUT if I change the dates in the range, the listbox items don't change to display the new dates. I would have expected the list items to change to reflect the new dates in the range.
I've attached my procedure code for reference.
Private Sub Worksheet_Activate
'This should update the list every time the user moves to the sheet
For Row = 2 to 20
If Sheets("Tables").Cells(Row, 10) > Date Then
ListBox1.Addition Sheets("Tables").Cells(Row, 10)
ListBox1.Addition Sheets("Tables").Cells(Row + 1, 10)
Row = 99 '(Yes, n ugly way of exiting a loop !!)