Autohide row base on numerical value input in a cell

4inthemorning

New Member
Joined
Oct 7, 2011
Messages
13
I am not well verse in MSExcel 2007,

I am hoping someone can help me with my problem. I am creating an excel file that will help my work more accurate and more faster. I have posted an image also for reference.

Is is possible to auto hide a row base on numerical value input in a cell?

Example:

I have maximum of 7 years of service, Now if I input the numbers of years needed(e.g. 4 years) the rows exceeding 4 years should be automatically hide (e.g. year 5, year 6 and year 7).

Question.

Is there a function in excel that this situation can be done?

Thank you very much
hide-problem.jpg
 
Try adding the blue lines
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim yrs As Long
    
    If Not Intersect(Target, Range("B5")) Is Nothing Then
        Application.ScreenUpdating = False
        ActiveSheet.Unprotect Password:="123456"
        yrs = Range("B5").Value
        Rows("11:17").Hidden = False
        If yrs < 7 Then
            Rows(11).Offset(yrs).Resize(7 - yrs).Hidden = True
        End If
        ActiveSheet.Protect Password:="123456"
        Application.ScreenUpdating = True
    End If
End Sub
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Thank you so much sir peter. It works now i dont really know how to thank you.
Glad we got there in the end. :)

BTW, for future reference, you will get many more potential helpers if you post any sample data in small screen shots directly in your post. That way people do not have to go to another site to look and also they can copy your sample data to a worksheet to test. My signature block has three ways to do that. Test them in the Test Here forum. That way, if something goes wrong, you won’t be messing up a main forum.
 
Upvote 0
It is possible that your code is not working because 'Events' (eg Worksheet_Change) are disabled. In the VBA window, ensure the Immediate Window is visible (View|Immediate Window) and then on a new line in the Immediate Window, type
Application.EnableEvents=True and press Enter
Now go back to your sheet and try again
 
Upvote 0
Error:

The macros in this project are disabled. Please refer to the online help or documentation of the host application to determine how to enable macros.
 
Upvote 0
Please refer to the online help or documentation of the host application to determine how to enable macros.
That was good advice. Did you try it? ;)

Help is the blue circle with ? near the top right of the Excel window.
Search for 'enable macros' .
Then look for the section 'Enable or disable macros with the Trust Center'.
Then the part that relates to Excel.
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,103
Members
452,379
Latest member
IainTru

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