Rows displayed dependent on cell value

Ranger22

New Member
Joined
Dec 3, 2013
Messages
28
Hello!
I need to create an excel sheet that will be filled in by individuals but the contents of the sheet are dependent on the answer of cell B2.
If B2 is Yes then the below is displayed:

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Credit[/TD]
[TD]Yes[/TD]
[/TR]
[TR]
[TD]Name[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Surname[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Address[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]







If B2 is No then the below is displayed:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Credit[/TD]
[TD]No[/TD]
[/TR]
[TR]
[TD]Name[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Is this done by a macro?

Your help is greatly appreciated.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
This is sheet code for the sheet that will be filled in. I assumed you want all rows to show when B2 is empty or filled with "yes".
To install sheet code:
1. Right-click the worksheet tab you want to apply it to and choose 'View Code'. This will open the VBE window.
2. Copy the code below from your browser window and paste it into the white space in the VBE window.
3. Close the VBE window and Save the workbook. If you are using Excel 2007 or a later version do a SaveAs and save it as a macro-enabled workbook (.xlsm file extension).
4. Make sure you have enabled macros whenever you open the file or the code will not run.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B2")) Is Nothing Then
    If LCase(Target) = "no" Then
        Target.Offset(2, 0).Resize(2, 1).EntireRow.Hidden = True
    Else
        Target.Offset(2, 0).Resize(2, 1).EntireRow.Hidden = False
    End If
End If
End Sub
 
Upvote 0
Perhaps this, in the Sheet module:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B2")) Is Nothing Then
    Select Case Range("B2").Value
        Case "Yes"
            Rows(4).Hidden = False
            Rows(5).Hidden = False
        Case "No"
            Rows(4).Hidden = True
            Rows(5).Hidden = True
        Case ""
            Rows(4).Hidden = True
            Rows(5).Hidden = True
    End Select
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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