MeisterConrad
New Member
- Joined
- Jan 17, 2017
- Messages
- 42
- Office Version
- 2007
In redesigning a Workbook, I have a UserForm with a ListBox that lists various Tables. I want to be able to click on any of the Table names in the ListBox as a means of selecting that Table for view/editing.
I'm trying to clean up the following code (old code for an older version of the Workbook) and make it more efficient:
I'm replacing it with:
...But it isn't working. What am I doing wrong?
Thanks for the help.
I'm trying to clean up the following code (old code for an older version of the Workbook) and make it more efficient:
VBA Code:
Private Sub ListBox1_Click()
If ListBox1.Selected(0) = True Then
Range("Table1").Select
Range("D" & Rows.Count).End(xlUp).Select
End If
If ListBox1.Selected(1) = True Then
Range("Table2").Select
Range("R" & Rows.Count).End(xlUp).Select
End If
If ListBox1.Selected(2) = True Then
Range("Table3").Select
Range("AF" & Rows.Count).End(xlUp).Select
End If
'... and on and on through all the items in the ListBox
End Sub
I'm replacing it with:
VBA Code:
Private Sub ListBox1_Click()
For i = 1 To 35
If ListBox1.Selected(i) = True Then
Range("LedgerTable" & i).Select
Range("E" & Rows.Count).End(xlUp).Select
End If
Exit For
Next i
End Sub
...But it isn't working. What am I doing wrong?
Thanks for the help.