VBA to hide/unhide

manc

Active Member
Joined
Feb 26, 2010
Messages
340
Good afternoon,

I have the following code:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) 
    If Not Target.Address = "a1" Then 
        Rows("2:5").Hidden = False 
    Else 
        Exit Sub 
    End If 
End Sub 
 
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) 
    If Target.Address <> "$a$1" Then 
        Rows("2:5").Hidden = True 
    Else 
        Exit Sub 
    End If 
End Sub

At present if I double-click on cell A1, rows 2 through 5 UNHIDE. If I right-click on cell A1, rows 2 through 5 HIDE.
Obviously right-clicking on a cell is not the best option.

I want to change this code so that If I click on cell A1, rows 2 through 5 UNHIDE, and If I click AGAIN on cell A1, rows 2 through 5 HIDE.

Any comments greatly received.

Best Regards
manc
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,214,943
Messages
6,122,376
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top