noname91
06-29-2018, 04:34 AM
Hi,
I'm experiencing a problem that I believe is stemming from the use of the Else function. Basically, my setup is such that if I click on row 2, a range of rows below it will be hidden if the rows are visible, and will become visible once row 2 is clicked again. This seems to be working, except that I can't click anywhere else after clicking on row 2 (i.e. I can click elsewhere, but the cursor instantly snaps back to the range of rows targeted for hiding). The code is below:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row = 2 And Rows("3:9").Hidden = False Then
Rows("3:9").Select
Selection.EntireRow.Hidden = True
Else
Rows("3:9").Select
Selection.EntireRow.Hidden = False
End If
End Sub
More than likely its the Else function that's causing, but I'm not sure what workaround would be the best. Any guidance here would be appreciated.
Thanks!
I'm experiencing a problem that I believe is stemming from the use of the Else function. Basically, my setup is such that if I click on row 2, a range of rows below it will be hidden if the rows are visible, and will become visible once row 2 is clicked again. This seems to be working, except that I can't click anywhere else after clicking on row 2 (i.e. I can click elsewhere, but the cursor instantly snaps back to the range of rows targeted for hiding). The code is below:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row = 2 And Rows("3:9").Hidden = False Then
Rows("3:9").Select
Selection.EntireRow.Hidden = True
Else
Rows("3:9").Select
Selection.EntireRow.Hidden = False
End If
End Sub
More than likely its the Else function that's causing, but I'm not sure what workaround would be the best. Any guidance here would be appreciated.
Thanks!