I'm using the code below to hide or unhide and activate worksheets in my workbook. I would like to add code to deselect the original selection in the listbox, however when I try to add code to several places I receive a Run-Time 9 error, subscript out of range.
Code I have tried:
and...
I'm sure this has to do with the FOR statement, but I'm not sure what the issue is or how to resolve. Any help would be great.
Code:
Private Sub lbSheets_Change()
Dim i As Integer, sht As String
For i = 0 To lbSheets.ListCount - 1
If lbSheets.Selected(i) = True Then
sht = lbSheets.List(i)
End If
Next i
If Sheets(sht).Visible = True Then
Sheets(sht).Visible = False
Exit Sub
ElseIf Sheets(sht).Visible = False Then
Sheets(sht).Visible = True
Sheets(sht).Activate
End
End If
End
End Sub
Code I have tried:
Code:
For x = 0 To lbSheets.ListCount - 1
If lbSheets.Selected(x) = True Then
lbSheets.Selected(x) = False
End If
Next
End
and...
Code:
frmManageSheets.Listbox1.Listindex=-1
I'm sure this has to do with the FOR statement, but I'm not sure what the issue is or how to resolve. Any help would be great.