Hide rows based on max value of column

mgchurch77

New Member
Joined
Aug 15, 2011
Messages
33
I am trying to run some code that will hide a row if a certain max value of a column is reached. I am fine with any solution to this whether it be that the macro determines the max from a column and then runs the hide function or if the max value is determined on the sheet with a Max(B2:B50) function. The latter is the approach that I have recently tried however I don't think that the "Private Sub Worksheet_Change(ByVal Target As Range" approach is picking up the change in the target cell which contains the MAX(B2:B50) funciton as when I force the sheet to hit the max value that is my target value, nothing hides.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Where the target cell contains the MAX() function:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$U$97" Then
Application.EnableEvents = False
If Target.Value = 2 Then
Rows("98:99").EntireRow.Hidden = True
Else
Rows("98:99").EntireRow.Hidden = False
End If
Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Hi there,

Please insert below code in the module of the sheet where you want to have those two rows hidden/unhidden:

Code:
Private Sub Worksheet_Calculate()
    Application.EnableEvents = False
 
    If ThisWorkbook.ActiveSheet.Cells(97, 21).Value = 2 Then
 
    ThisWorkbook.ActiveSheet.Range("U98:U99").EntireRow.Hidden = True
    Else
    ThisWorkbook.ActiveSheet.Range("U98:U99").EntireRow.Hidden = False
    End If
 
    Application.EnableEvents = True
End Sub

I have tried it myself on a sample file, it works just fine.

Please confirm the code I propose above solves your request, as expected. Thank you.
 
Upvote 0

Forum statistics

Threads
1,224,578
Messages
6,179,654
Members
452,934
Latest member
mm1t1

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