Macro Hide Sheet2-11 based on Yes/No questions on Sheet1

hschorsch

New Member
Joined
Feb 22, 2015
Messages
6
Hi, still very new at macros and could use some assistance,

On the sheet "WorkBookSetUp" I am putting drop boxes in Column F starting with Row 3 and extending to row 13. Each will have option of Yes or No. I would like the other sheets in the work book to appear if yes is selected and disappear if no is selected. My first sheet to disappear/reappear is called "AcidCalculator".

Digging through the forums here and elsewhere I got the following macro, copied it into the code box for "workbooksetup" filled in the sheet name and the reference, hit run but I get a compile error "end if without block if" which i do not understand. Can someone please assist me in correcting my errors so I can complete this project.

Private Sub Worksheet_Change(ByVal Target As Range)
If "f3" = "yes" Then
Sheets("AcidCalculator").Visible = True​
Else​
Sheets("AcidCalculator").Visible = False​
End If​
End If
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,527
Office Version
  1. 2019
Platform
  1. Windows
Hi,
you get the error because you have an extra Endif in your code:

Rich (BB code):
If "f3" = "yes" ThenSheets("AcidCalculator").Visible = True
Else
Sheets("AcidCalculator").Visible = False
End If
End If

but you can do what you want with a single line:

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets("AcidCalculator").Visible = Not Me.Range("f3").Value = "yes"
End Sub

Dave
 

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
5,182
Office Version
  1. 2013
Platform
  1. Windows
Maybe look to deal with all 10 rows using.....

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("F3:F13")) Is Nothing Then Exit Sub
If Target.Cells.Count > 1 Then Exit Sub
Select Case Target.Row
Case 3
ShtName = "AcidCalculator"  'edit sheet namesbelow to suit the row number
Case 4
ShtName = "Second sheet"
Case 5
ShtName = "Third sheet"
Case 6
ShtName = "etc etc"
Case 7
ShtName = "etc etc"
Case 8
ShtName = "etc etc"
Case 9
ShtName = "etc etc"
Case 10
ShtName = "etc etc"
Case 11
ShtName = "etc etc"
Case 12
ShtName = "etc etc"
Case 13
ShtName = "etc etc"


End Select
On Error Resume Next
Sheets(ShtName).Visible = LCase(Target) = "yes"
On Error GoTo 0
End Sub

Hope that helps.
 

hschorsch

New Member
Joined
Feb 22, 2015
Messages
6
Thank you dmt32 your single line code was perfect for my needs.

Honestly I didn't test your version Snakehips since the other solution worked so easily for me but thank you for replying too.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,307
Messages
5,641,439
Members
417,209
Latest member
Agbarker

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
Top