Hide and unhide row based on cell value

rintelen

Board Regular
Joined
Jul 30, 2006
Messages
96
I have a spreadsheet with a value in GB12 that is either 0 or 1.

When the value of GB12= 0 I want Row 9 to remain or be un-hidden (visible).

But when GB12 = 1 I want row 9 to be hidden.

How can I do this please?

I'm very stupid at excel so you need to walk me through the process of how I can make this macro only apply to this one sheet (the excel sheet has many tabs) so that it updates all the time.

The sheets name is PV Calculator.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
right click on sheet name--> view code , then paste this
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(0, 0) <> "GB12" Then Exit Sub
Rows("9").Hidden = Range("GB12").Value = 0
End Sub
 
Upvote 0
Right click on the "PV Calculator " sheet tab and select "View Code"
In the left hand window, double click on the sheet "PV Calculator"

Now paste the code I provided in the right hand windowSave and close the window.

It should now work as required.

Code:
Sub worksheet_selectionChange(ByVal target As Range)
If Range("GB12").Value = 1 Then Rows(9).EntireRow.Hidden = True
If Range("GB12").Value = 0 Then Rows(9).EntireRow.Hidden = False
End Sub

I believe they will both do as required, but the code from Yahya will be more efficient.
 
Upvote 0
This I hope would work but there is already a macro in that part. So when I do View code I see this:


Private Sub worksheet_selectionChange(ByVal target As Excel.Range)
With target
If .Count > 1 Then Exit Sub
If .Address(False, False) = "C17" Then _
Range("C18").ClearContents
If .Address(False, False) = "C17" Then _
Range("C75").ClearContents
End With
End Sub

If I paste your routine after or before this it doesn't work. What do I need to do please?

Also will these hide and unhide the row or will it just do it once?
 
Last edited:
Upvote 0
It works on its own without the above but it doesn't update until I click something on the sheet? I want it to be instant. But I do need the above. So How can I get both to work please.
 
Last edited:
Upvote 0
I'm wrong. It does work but I have to click somethign before it fires up.

I need it to be instantly updated upon arrival at that sheet.

But I cannot make it work if I have that other macro there. I need both to work.
 
Upvote 0
You can't have more than one instance of a macro in a Worksheet_Change event.
So, if you have to run 2 macros via that method, you will need to combine them.
 
Upvote 0
How do I combine them please? And keep the protection switched on during each phase of hide or unhide when the value changes.
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,626
Members
452,933
Latest member
patv

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