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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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,224,590
Messages
6,179,756
Members
452,940
Latest member
rootytrip

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