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
 

VBA Geek

MrExcel MVP
Joined
Dec 16, 2013
Messages
2,857
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
 

jackmceachen

New Member
Joined
Mar 12, 2014
Messages
3
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)
 

VBA Geek

MrExcel MVP
Joined
Dec 16, 2013
Messages
2,857
you have to enter it between privatesub_commandbutton1_click() and end sub

exclude from my code the lines

Sub de()

End Sub
 

Forum statistics

Threads
1,081,615
Messages
5,360,037
Members
400,565
Latest member
Tommy O

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top