Find Worksheet based on Value

quanweitkd

New Member
Joined
Apr 8, 2021
Messages
22
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a raw data report with up to 100 worksheets. There are a few worksheets that contains "No records found" showing on cell A4.
Is there a VBA code that can loop through all the worksheets and make the first occurrence of "no record found" worksheet active?
I have tried more than 10 solutions online but all failed.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try:
Edited

VBA Code:
Sub FindFirstEmptySheet()

    Dim sht As Worksheet
  
    For Each sht In Worksheets
        If InStr(1, sht.Range("A4"), "No records found", vbTextCompare) Then
            sht.Activate
        End If
    Next sht

End Sub
 
Upvote 0
Oops try this one:
VBA Code:
Sub FindFirstEmptySheet()

    Dim sht As Worksheet
    
    For Each sht In Worksheets
        If InStr(1, sht.Range("A4"), "No records found", vbTextCompare) Then
            'Debug.Print sht.Name
            sht.Activate
            Exit For
        End If
    Next sht

End Sub
 
Upvote 0
Although the above works I should have done something like this:
(if you are sure its an exact match you can remove the UCase from both sides)

VBA Code:
Sub FindFirstEmptySheet()

    Dim sht As Worksheet
  
    For Each sht In Worksheets
        If UCase(sht.Range("A4")) = UCase("No records found") Then
            sht.Activate
            Exit For
        End If
    Next sht

End Sub
 
Upvote 0
Upvote 0
Sharepoint often does not allow Public Links to be sent out. Can you use google drive, drop box or another sharing platform and make it available to anyone with the link. I can't get to your file.
Just to be sure you need to send it to me, can you try my macro in post #4 first, to see if it makes any difference.
 
Upvote 0
Sharepoint often does not allow Public Links to be sent out. Can you use google drive, drop box or another sharing platform and make it available to anyone with the link. I can't get to your file.
Just to be sure you need to send it to me, can you try my macro in post #4 first, to see if it makes any difference.
I have tried the macro on post #4 also no response.
You can access my file via this Notion link. This is not the original work file, hence sharing it on public platform is ok.


Appreciate your help!
 
Upvote 0
I had the search text wrong no "s" and you have an exclamation mark as well, here it is updated.

VBA Code:
Sub FindFirstEmptySheet()

    Dim sht As Worksheet
  
    For Each sht In Worksheets
        Debug.Print sht.Name & "-" & sht.Range("A4")
        If UCase(sht.Range("A4")) = UCase("No record found!") Then
            sht.Activate
            Exit For
        End If
    Next sht

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,813
Messages
6,127,029
Members
449,355
Latest member
g wiggle

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