Excel VBA Listbox use of SelectedIndexChanged event

Mike Wojcik picture Mike Wojcik · Apr 26, 2017 · Viewed 7.6k times · Source

I am trying to utilize the Excel VBA Listbox SelectedIndexChanged event to update a textbox on the same userform with the sum of the values in one column of my listbox as the user selects each row in that listbox.

I can not figure out how to get the code for that event handler to execute. Any suggestions? I am using Excel VBA with the latest version of excel from office 365 on a windows 10 machine. In fact i don't even see that event listed in the pulldown when i have the code window up for that userform?

Thanks Mike

Answer

shakespeare picture shakespeare · Apr 27, 2017
Private Sub ListBox1_Change()
  // Your can do anything with it

  // Looping here
     For i = 0 To ListBox1.ListCount - 1
       If ListBox1.Selected(i) Then
        ListBox1.Selected(i) = False
       End If
     Next
  End Sub