Searching and unhiding specific worksheets using VB

jackmceachen

New Member
Joined
Mar 12, 2014
Messages
3
I have five worksheets hidden in my workbook. All of these worksheets have either "Yes" or "No" written in cell C4. (3-yes, 2-no)

I also have a search bar in the form of a textbox and a command button.

I want to be able to type "No" in the textbox, click the command button and have the pages with "No" in cell C4 to unhide.

I have no clue as to how I could do this, and I'm somewhat new to Excel, so if you could explain to me exactly what to write in the VB on the command button I would be very grateful.

Some screenshots if necessary:
Sheet1 (yes): Gyazo - ce85d71bc03cd2ceaa1030e22445800f.png
Sheet2 (no): Gyazo - 65f876d6e7d749bd1ca25ad957fbda99.png
Sheet3 (yes): Gyazo - 0cb442f1d34e7d744884f73e1afe2646.png
Sheet4 (yes): Gyazo - 6f0ce150322208fd93dc5fc6f4f66481.png
Sheet5 (no): Gyazo - 772f48f8a82e53713794e6655fe56fca.png
master: Gyazo - 1b71470f3de47cef347050588bca819c.png
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Code:
Sub de()
Dim V As Variant
Dim RT As String
RT = InputBox("Yes or No?")
If InStr("NOYES", UCase(RT)) = 0 Then MsgBox "Invalid input": Exit Sub
For Each V In Array("D", "E", "K", "W") ' D E K W represent the names of of your worksheets
    With Worksheets(V)
        If UCase(.Range("C4").Value) = UCase(RT) Then
            .Visible = True
        Else
            .Visible = False
        End If
    End With
Next
End Sub
 
Upvote 0
Right, this is what I've entered into VB: Gyazo - a8efb9bd5e4d7fbfb9f86856e2cded6a.png

When I press the button, nothing happens, not even the debugger appears.

Although I'm fairly (very) sure I've entered the code wrong, could you write out exactly what I need for it to work.

(Basically if I copy and paste the code into VB, click the button, it'll work)

(Apologies for being so basic)
 
Upvote 0
you have to enter it between privatesub_commandbutton1_click() and end sub

exclude from my code the lines

Sub de()

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,114,002
Members
448,543
Latest member
MartinLarkin

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