ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   MultiColumn ListBox, linked to a range - select cells (https://www.excelbanter.com/excel-programming/325782-multicolumn-listbox-linked-range-select-cells.html)

Spencer Hutton

MultiColumn ListBox, linked to a range - select cells
 
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.

Dave Peterson[_5_]

MultiColumn ListBox, linked to a range - select cells
 
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



Spencer Hutton wrote:

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.


--

Dave Peterson


All times are GMT +1. The time now is 01:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com