Auto hide/unhide rows VBA

abmyers

New Member
Joined
Jul 28, 2011
Messages
7
This will be the first time I've ever used code so thanks in advance for your patience with my ignorance. I'd like to have a macro that hides rows based on a condition.

In cell g3 I have a formula that counts the number of entries from another table that meet certain criteria.

I'd like to hide rows in a range based on the results of cell g3. Basically I want to hide row (19+g3):row(500)

So..

If g3=121, I would hide row 140:500.
If g3=0 I would hide row 19:500

Etc...

One more thing I need this to automatically hid/unhide based on changes to the number in G3

Thanks in advance
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A1:A10")) Is Nothing Then 'This is the range that triggers G3 to update, not G3 itself.

ActiveSheet.Rows("19:500").EntireRow.Hidden = False

Dim NumRows as Integer

NumRows = ActiveSheet.Range("G3").Value
NumRows = NumRows + 19
ActiveSheet.Rows(NumRows & ":500").EntireRow.Hidden = True
End If


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

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