Vba to hide rows based on a cell within another worksheet

tomwhi

New Member
Joined
May 13, 2013
Messages
35
Hello,

Please can I ask for your help again.

I am looking for VBA to Hide Rows (37:38), Based on value ("No") of a cell (D26) in another worksheet (Control Center). If cell D26 in worksheet "Control Center" is blank or "Yes", I do NOT want hide the row.

Thanks,
Tom
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi Tom,

Find the following code to hide rows based on cell D26 in "Control Center" sheet.
If cell value is "No", then it hides rows 37 & 38 on "Output" sheet.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
     
    If Target.Address = "$C$26" Then
        If Target.Value = "No" Then
            Sheets("Output").Rows("37:38").EntireRow.Hidden = True
        Else
            Sheets("Output").Rows("37:38").EntireRow.Hidden = False
        End If
    End If
End Sub


Place the above code under sheet "Control Center" code module.
For more understanding find Attached File at Box.

Thanks,
Mahesh
 
Last edited:
Upvote 0
Mahesh's should work
 
Last edited:
Upvote 0
Hey Mahesh, Momentman,

I have an additional question. Is there away to change the code slightly so that it is driven from a formula, rather than a 'change'? i.e. C26, would be a formula, with the result being Yes, No or "".

Thanks
Tom
 
Upvote 0
A change simply means once the cell recalculates, so whether you have a formula in the cell, it shouldn't matter. The code would still work
 
Upvote 0
Hi Momentman,

There is a Worksheet_Calculate() event procedure in excel. procedure is triggered by any change in a formula.
The below code should work for you.

Private Sub Worksheet_Calculate()
Dim MyRange As Range
Set MyRange = Sheets("Control Center").Range("C26")
If MyRange.Value = "No" Then
Sheets("Output").Rows("37:38").EntireRow.Hidden = True
Else
Sheets("Output").Rows("37:38").EntireRow.Hidden = False
End If
End Sub

Thanks,
Mahesh
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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