troubleshooting Question

How do I update an Excel ListBox form control in VBA

Avatar of Tocogroup
TocogroupFlag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft Excel
5 Comments1 Solution541 ViewsLast Modified:
Hi,

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.

Thanks
Toco
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 !!)
   End If
Next Row

End Sub
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros