Hide rows with macro

  • Thread starter Thread starter Fugazy
  • Start date Start date
F

Fugazy

I have a question about hiding and unhiding rows with a Macro. I hav
searched trough the forum but I couldn't find the right solution for m
specific problem.

The situation is as follows:

I have a sheet that I want to make a bit smaller, by hiding rows. Th
amount of visible rows can be entered in cell F7. The rows that shoul
be hidden are rows 14 till 25.

So if the number of visible rows entered in cell F7 is 1, row 1
unhides, if it's 2 row 14&15 unhide etc.

Is there a way to do this in a Macro?

Many thanks in advance for your help.

ps. I'm sorry for any grammar or spelling mistakes, English is not m
mother language :
 
Paste the following code in your Worksheet's code
(right-click tab, select View code)

HTH
--
AP

'----------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rNbRow As Range
Dim lrow As Long

Set rNbRow = Range("F7")
If Intersect(Target, rNbRow) Is Nothing Then Exit Sub
For lrow = 14 To 25
Rows(lrow).Hidden = lrow >= rNbRow.Value + 14
Next lrow

End Sub
'------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top