vba script to unhide next tab only if a cell value is correct

ennakkadan

New Member
Joined
Nov 10, 2014
Messages
3
I have to create a database form. I want to unhide next sheet with the same fields only if the value of a particular cell is correct. For instance - the answer to question "Do you want to add more?" is "Yes" then the next sheet will appear, otherwise will remain hidden. Same way if the same cell value in that sheet turns "Yes" next sheet will appear and so on. Can someone help me. BTW the work book is created in .xlsx. Thanks in advance.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Welcome to the MrExcel board!

the work book is created in .xlsx
For your request to be implemented, that will have to change to a .xlsm


.. if the same cell value in that sheet turns "Yes" ..
How does the cell change to "Yes"?
a) Is there formula in the cell that may return "Yes"
b) Does the user manually enter "Yes" in the cell when appropriate?
c) Something else? What?

What is the cell address that would contain this "Yes"? (I assume that it would be the same cell in all the relevant sheets)
 
Upvote 0
Hello Peter, Thanks for your reply.

For your request to be implemented, that will have to change to a .xlsm - Thanks. This means I have to save the same in .xlsm

The "Yes" would be selected from a drop down menu. The Cell address would be same in all the sheets. In my Data sheet the cell is "B34"

Regards
Ennakkadan
 
Upvote 0
The "Yes" would be selected from a drop down menu. The Cell address would be same in all the sheets. In my Data sheet the cell is "B34"
OK, try this in a copy of your workbook saved as a macro-enabled file (*.xlsm).

1. With the workbook active, open the vba editor (Alt+F11)
2. Double click the 'ThisWorkbook' module of your project in the left hand pane.
3. Paste the code below into the main right hand pane that appeared after step 2.
4. Close the Visual Basic window and test by changing cell B34 in your right-most visible sheet to "Yes" with your drop-down.

Rich (BB code):
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  Const UnhideCell As String = "B34"
  
  If Not Intersect(Target, Sh.Range(UnhideCell)) Is Nothing Then
    If LCase(Sh.Range(UnhideCell).Value) = "yes" Then
      If Sh.Index < Sheets.Count Then
        Sheets(Sh.Index + 1).Visible = True
      End If
    End If
  End If
End Sub
 
Upvote 0
Glad it helped. Thanks for letting us know.
 
Upvote 0

Forum statistics

Threads
1,215,741
Messages
6,126,592
Members
449,320
Latest member
Antonino90

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