Macro Issues - Search for call value in a range

HNoble

New Member
Joined
May 21, 2019
Messages
13
Hi All

Can someone please help with my issue. Basically I have a workbook that has a Template tab, Home Page tab, Reports tab plus mutiple project tabs with different names.

On the Home Page tab I have a search box where I will enter a project tab name to search it in the open tabs. The code is working but only when I type out the value as shown in the range on the project tab. Is there a way of searching the range and bringing back anything that is contained? Or is there a different way completely.

Here is my code:


Dim ws As Worksheet, WRD As String, loc As Range

WRD = Sheets("Home Page").Range("F27").Value
For Each ws In Worksheets
ws.Visible = True
Next

For Each ws In Worksheets
If ws.Name <> "Template" And ws.Name <> "Home Page" And ws.Name <> "Reports" Then ws.Visible = xlSheetVisible
With ws
Set loc = .Range("C1:E8").Find(What:=WRD, SearchDirection:=xlNext)
If loc Is Nothing Then ws.Visible = xlSheetHidden

End With
Next ws


Any help is appreciated. Thanks!
Hannah
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Please clarify based on this example ..

3 of the project tab names are :
Mouse
Dormouse
Mousehole

user enters mouse into F27 and runs the macro ..

What should happen next ?
- hide all sheets except those 3
- something different ?
 
Upvote 0
Try this

Code:
Sub test()
  Dim ws As Worksheet, WRD As String, loc As Range
  Application.ScreenUpdating = False
  WRD = Sheets("Home Page").Range("F27").Value
  For Each ws In Worksheets
    Select Case ws.Name
      Case "Template", "Home Page", "Reports"
      Case Else
        Set loc = ws.Range("C1:E8").Find(What:=WRD, LookIn:=xlValues,[COLOR=#0000ff] lookat:=xlPart[/COLOR])
        If Not loc Is Nothing Then
          ws.Visible = xlSheetVisible
        Else
          ws.Visible = xlSheetHidden
        End If
      End Select
  Next ws
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,054
Latest member
juliecooper255

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