Hide Unhide entire row

rakupareek

New Member
Joined
Dec 29, 2023
Messages
38
Office Version
  1. 2016
Platform
  1. Windows
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim ToggleCell As Range
Dim HiddenRows As Range
Set ToggleCell = Range("B5")
If Not Intersect(Target, ToggleCell) Is Nothing Then
Set HiddenRows = Range("6:13")
HiddenRows.EntireRow.Hidden = Not HiddenRows.EntireRow.Hidden
Cancel = True
ElseIf Target.Row = 14 And Target.Column = 2 Then
Set HiddenRows = Range("15:16,23:24")
HiddenRows.EntireRow.Hidden = Not HiddenRows.EntireRow.Hidden
Cancel = True
ElseIf Target.Row = 15 And Target.Column = 2 Then
Set HiddenRows = Range("16:22")
HiddenRows.EntireRow.Hidden = Not HiddenRows.EntireRow.Hidden
Cancel = True
ElseIf Target.Row = 23 And Target.Column = 2 Then
Set HiddenRows = Range("24:30")
HiddenRows.EntireRow.Hidden = Not HiddenRows.EntireRow.Hidden
Cancel = True
ElseIf Target.Address = "$C$15" Then
Worksheets("Anx-1").Activate
Cancel = True
ElseIf Target.Address = "$C$23" Then
Worksheets("Anx-2").Activate
Cancel = True
End If

End Sub
Hi
I am Using above code to hide and unhide rows but I want to know that
WHEN I DOUBLE CLICK ON ROW 15 THEN HIDE ROW 16:22 AND WHEN I RECLICK ON ROW 15 THEN UNHIDE ONLY NEXT ROW TO LAST FILL ROW (FROM SET RANGE 16:22)
AS IT IS WHEN I DOUBLE CLICK ON ROW 23 THEN HIDE ROW 24:30 AND WHEN I RECLICK ON ROW 23 THEN UNHIDE ONLY NEXT ROW TO LAST FILL ROW(FROM SET RANGE 24:30)
Is it possible????
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Since I'm unable to patch your macro I propose my version. In the sheet you will need to use two helper cells (AA1:AA2) to store the last used cell in Range("16:22") and Range("24:30") and manually valorize them (it would need other macro to have this done automatically and that's where I'm banging my head). There should still be an issue because I have the feeling that there is something wrong in your second uppercase line in post #1. Anyway, after pasting and setting Save/Open the file and have a try.
Macro to be pasted in ThisWorkBook's module:
VBA Code:
Option Explicit
Private Sub Workbook_Open()
    With Sheets(1)                                '<-adjust sheet index or name as needed
        LCF15 = .Range("AA1")
        LCF23 = .Range("AA2")
    End With
End Sub
and this to be pasted into the sheet's module (replaces your macro):
Code:
Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim RowsToHide As Range
    If Intersect(Target, Range("$B$5, $B$14, $B$15, $B$23, $C$15, $C$23")) Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Select Case Target.Address
        Case Is = "$B$5"
            Set RowsToHide = Range("6:13")
        Case Is = "$B$14"
            Set RowsToHide = Range("15:16,23:24")
        Case Is = "$B$15"
            Set RowsToHide = Range("16:22")
        Case Is = "$B$23"
            Set RowsToHide = Range("24:30")
        Case Is = "$C$15"
            Worksheets("Anx-1").Activate
        Case Is = "$C$23"
            Worksheets("Anx-2").Activate
    End Select
    If Intersect(Target, Range("$C$15, $C$23")) Is Nothing Then RowsToHide.EntireRow.Hidden = Not RowsToHide.EntireRow.Hidden
    If Not Intersect(Target, Range("$B$15, $B$23")) Is Nothing Then
        Select Case Target.Address
            Case Is = "$B$15"
                Set RowsToHide = Range(LCF15 + 1 & ":22")
            Case Is = "$B$23"
                Set RowsToHide = Range(LCF23 + 1 & ":30")
        End Select
        RowsToHide.EntireRow.Hidden = True
    End If
    Cancel = True
    Application.ScreenUpdating = True
End Sub
and this other in a standard module:
Code:
Option Explicit
Public LCF15  As Long
Public LCF23  As Long
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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