MultiColumn ListBox, linked to a range - select cells

G

Guest

i have a multicolumn list box, "ListBox1", with this statement on it's click
event.
Private Sub ListBox1_Click()
If ListBox1.ListIndex <> -1 Then
Rows(ListBox1.ListIndex + 2).Select
End If
End Sub

i have made this list box a MultiSelect listbox. how can i modify this code
to make it select the multiple rows as if the user was holding Ctrl and
selecting rows? TIA.
 
D

Dave Peterson

I changed the procedure to _change.

Option Explicit
Private Sub ListBox1_Change()

Dim iCtr As Long
Dim Rng As Range

For iCtr = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(iCtr) = True Then
If Rng Is Nothing Then
Set Rng = Cells(iCtr + 2, "A")
Else
Set Rng = Union(Cells(iCtr + 2, "A"), Rng)
End If
End If
Next iCtr

If Rng Is Nothing Then
'do nothing
Else
Rng.EntireRow.Select
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top