Code for hiding rows w/ list

mcwilson

New Member
Joined
Jun 21, 2011
Messages
19
Hello all,

I have a list in A91 where the user can select 1, 2, or 3.
If 1 is selected, i want rows 92 and 93 to be hidden.
if 2 is slected, i want row 93 to be hidden
if 3 is selected, i want everything to show.

Any ideas on how/if this can be done, please let me know.

Thanks in advance and God bless
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "A91" Then
Select Case Target.Value
    Case 1: Rows("92:93").Hidden = True
    Case 2: Rows("93").Hidden = True: Rows("92").Hidden = False
    Case 3: Rows("92:93").Hidden = False
End Select
End Sub
 
Upvote 0
Sorry, I missed an End If. Tested and working here

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "A91" Then
    Select Case Target.Value
        Case 1: Rows("92:93").Hidden = True
        Case 2: Rows("93").Hidden = True: Rows("92").Hidden = False
        Case 3: Rows("92:93").Hidden = False
    End Select
End If
End Sub
 
Upvote 0
Thanks for the help. Quick question though. If I were trying to do a macro instead, how would i go about doing that? This code works for the first subsequent row, but not the second one. ideas?

Sub HURows()
BeginRow = 91
EndRow = 140
ChkCol = 1
For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value = 1 Then
Cells(RowCnt + 1, ChkCol).EntireRow.Hidden = True
Else
Cells(RowCnt + 1, ChkCol).EntireRow.Hidden = False

End If

Next RowCnt
End Sub
 
Upvote 0
That was a macro :eek:

Try

Code:
Sub HURows()
Dim BeginRow As Long, EndRow As Long, ChkCol As Long, RowCnt As Long
BeginRow = 91
EndRow = 140
ChkCol = 1
For RowCnt = BeginRow To EndRow
    Cells(RowCnt, ChkCol).EntireRow.Hidden = Cells(RowCnt, ChkCol).Value = 1
Next RowCnt
End Sub
 
Upvote 0
the intended ones are the two below if it says #1
if the list says 2, then i want the third line hidden.

I apologize that I have this so confusing!
 
Upvote 0
When i am inserting that previous micro, when i right click on tab and select "view code" nothing appears. When i go to insert, what should i select?
If i then paste code into that, how do i get the micro to run?

sorry for being such a noobie./

God bless your patience!
 
Upvote 0
A regular macro should go in a regular module. Press ALT + F11 to open the Visual Basic editor, select Module from the Insert menu then enter the code.
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

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