Using VB to unhide hidden rows based on user response

L

Lost

I have 10 rows in groupings of 2 (total of 5 groupings) that are
hidden. Based on user input in a cell I want to unhide the rows.

The user will input a number from 1 to 5 in cell A15. Each number is
to unhide 2 rows progressively. (Currently 20/21, 22/23, 24/25, 26/27,
28/29)

Example:
User input of 1 will unhide 20 and 21. An input of 2 will unhide 20,
21, 22, and 23. An input of 3 will unhide 6 rows. Etc.

Can VB do this? (If so where can I find the code or can you write it
here.)

Can it be automatic anytime that cell is changed or will I need to
create a button to run the specified macro code. (The automatic is
better but will take what I can get.)

Any help you can offer would be apprecaited.

Dave
 
T

Tom Ogilvy

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
if Target.count > 1 then exit sub
if Target.Address = "$A$15" then
Rows(20).Resize(10).Hidden = True
if Target.Value >=1 and Target.Value <= 5 then _
Rows(20).Resize(Target.Value*2).Hidden = False
End if
End Sub

Right click on the sheet tab and select view code. Put in code similar to
the above code.
 
R

RU_Powers

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
if Target.count > 1 then exit sub
if Target.Address = "$A$15" then
Rows(20).Resize(10).Hidden = True
if Target.Value >=1 and Target.Value <= 5 then _
Rows(20).Resize(Target.Value*2).Hidden = False
End if
End Sub

Right click on the sheet tab and select view code. Put in code similar to
the above code.

Tom O provided some great code to hide/unhide rows on a sheet based on
a user input. I am running into a slight problem I need a little
guidance.

I have Sheet 1 and Sheet 5. I want the input from Sheet 1 to modify
the rows on sheet 5. I know this is wrong code but it is what I have
so far:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
' Checks Part Time Labor Types
If Target.Count > 1 Then Exit Sub
If Target.Address = "!Sheet1$F$16" Then
Rows(8).Resize(7).Hidden = True
If Target.Value >= 1 And Target.Value <= 5 Then _
Rows(8).Resize(Target.Value + 2).Hidden = False
End If
End Sub

I know the problem lies with the 4th live down. I want the user input
from cell F16 on sheet one to effect the rows on sheet 5. (In this
case row 8 and the following 7 rows.)

Can someone help fine tune that 4th line.

Thanks

RU
 

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

Top