Help with codes

eagle028

New Member
Joined
May 28, 2005
Messages
49
I've started my excel with the following codes.

I've in mind (if possible) to add a set of codes such that if i click on say Row3, then Row 4-9 will appear whilst row 10 onwards remain hidden. Is this possible?



Sub Worksheet_Change(ByVal Target As Range)

Select Case Target.Address 'first check which cell has been changed

Case "$D$8" 'if it's A1, run the A1 code
Select Case Target.Value
Case "Please select": Rows("10:34").EntireRow.Hidden = True
Case "1": Rows("9:14").EntireRow.Hidden = False
Rows("15:34").EntireRow.Hidden = True
Case "2": Rows("9:19").EntireRow.Hidden = False
Rows("20:34").EntireRow.Hidden = True
Case "3": Rows("9:24").EntireRow.Hidden = False
Rows("25:34").EntireRow.Hidden = True
Case "4": Rows("9:29").EntireRow.Hidden = False
Rows("30:34").EntireRow.Hidden = True
Case "5": Rows("9:34").EntireRow.Hidden = False
End Select

End sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try replacing that code with

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Select Case Target.Row
    Case 1: Rows("9:14").EntireRow.Hidden = False: Rows("15:34").EntireRow.Hidden = True
    Case 2: Rows("9:19").EntireRow.Hidden = False: Rows("20:34").EntireRow.Hidden = True
    Case 3: Rows("9:24").EntireRow.Hidden = False: Rows("25:34").EntireRow.Hidden = True
    Case 4: Rows("9:29").EntireRow.Hidden = False: Rows("30:34").EntireRow.Hidden = True
    Case 5: Rows("9:34").EntireRow.Hidden = False
End Select
End Sub
 
Upvote 0
I would like to keep the current codes but on top of that to have a code which enable me to do the following:

When I click on Row 3, Row 4-9 will appear whilst remaining rows remain hidden. I think it may be somewhat like a hyperlink function where when i click on the link, the Rows are unhidden.
 
Upvote 0
Try

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Select Case Target.Row
    Case 1: Rows("9:14").Hidden = False: Rows("15:34").Hidden = True
    Case 2: Rows("9:19").Hidden = False: Rows("20:34").Hidden = True
    Case 3: Rows("4:9").Hidden = False: Rows("10:34").Hidden = True
    Case 4: Rows("9:29").Hidden = False: Rows("30:34").Hidden = True
    Case 5: Rows("9:34").Hidden = False
End Select
End Sub
 
Upvote 0
Yes, it is done using this:

Rich (BB code):
Select Case Target.Row

Target is the cell that you clicked in, .Row gets the row number.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,492
Members
448,967
Latest member
visheshkotha

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