Private Sub Worksheet_Calculate()

nm079

New Member
Joined
Sep 15, 2011
Messages
4
Hi,

I am currently struggling with a Private Sub Worksheet_Calculate() macro.

I have 3 areas of my worksheet that I wish to hide / unhide under different conditions.

Unfortunately I am struggling to get 3 'IF' statements into the one sub.

Here's what I have:

Private Sub Worksheet_Calculate()

If Range("B70").Value = "No" Then

Range("71:71", "73:73").EntireRow.Hidden = True

Else

Range("71:71", "73:73").EntireRow.Hidden = False

End If

If Range("F94").Value = "No" Then

Range("86:86", "92:92").EntireRow.Hidden = True

Else

Range("86:86", "92:92").EntireRow.Hidden = False

End If

If Range("E94").Value = "No" Then


Range("68:68", "75:75").EntireRow.Hidden = True
Range("84:84", "86:86").EntireRow.Hidden = True

Else

Range("68:68", "75:75").EntireRow.Hidden = False
Range("84:84", "86:86").EntireRow.Hidden = False

End If

End Sub

I have also tried nesting the IF commands - but unfortunately only one of the conditions seem to work.

If anybody could shed some light on this I'd be really grateful as I've spent the past 2 days banging my head against a brick wall!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Welcome to the Board!

How is it not working?
What is (or isn't happening)?
What is happening that is supposed to trigger this macro?

Note that if you do NOT want to hide rows 72 along with 71 and 73, this will not work properly:
Code:
Range("71:71", "73:73").EntireRow.Hidden = True
It should look like this:
Code:
Range("71:71, 73:73").EntireRow.Hidden = True
 
Upvote 0
Thanks for your reply and welcome!

Two of the IF statements are working, however the middle IF doesn't seem to do anything:

If Range("F94").Value = "No" Then

Range("86:86", "92:92").EntireRow.Hidden = True

Else

Range("86:86", "92:92").EntireRow.Hidden = False

End If


The hide function is correct - I wish to hide a block of rows rather than just two.

For the record - I am using the calculate function as the target fields are set by a formula.
 
Upvote 0
Sorry - ignore that last reply.

It's the first IF statement that doesn't work.

When B70 is set to 'No' it should hide rows 71-73.

It does nothing.

The other IF statements hide their rows correctly based on the values in row 94.


Sorry for the confusion!
 
Upvote 0
Glad you got it figured out.

Note if you are looking to hide a block of rows, you can rewrite this:
Code:
Range("71:71", "73:73").EntireRow.Hidden = True
to this:
Code:
Rows("71:73").EntireRow.Hidden = True
Its a little shorter, and also a little clearer of what is happening.
 
Upvote 0

Forum statistics

Threads
1,215,652
Messages
6,126,037
Members
449,281
Latest member
redwine77

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