Searching Sheet Names using a wildcard

sGraham24

New Member
Joined
May 8, 2024
Messages
10
Office Version
  1. 365
  2. 2011
Platform
  1. Windows
Hello. I have this code which finds a blank line, goes up one cell in col A, takes the active cell value and searches for a sheet named that value. It is not finding all the sheets because the active cell value may not be the exact same value as the sheet name. [I.E. Active Cell is "227017.0.6230295.4.1" and the Sheet name is "6230295.4.1" Note this is just one example of hundreds.]

Is there a way to use a wildcard within this code so that if the sheet name contains the active cell value it will find it?

Sub FindFirstSlinAndSearchSheetNames()
Dim sourceCol As Integer
Dim rowCount As Integer
Dim CurrentRow As Integer
Dim currentRowValue As String
Dim SlinNum As String

'column A has a value of 1
sourceCol = 1
rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row

'for every row, find the first blank cell and select it
For CurrentRow = 1 To rowCount
currentRowValue = Cells(CurrentRow, sourceCol).Value

If IsEmpty(currentRowValue) Or currentRowValue = "" Then
Cells(CurrentRow, sourceCol).Select
Exit For
End If
Next

Dim myText As String

ActiveCell.Offset(-1, 0).Select
myText = ActiveCell.Value

Dim ws As Worksheet
Dim foundSheet As String
foundSheet = ""

For Each ws In ThisWorkbook.Worksheets
If InStr(1, ws.Name, myText, vbTextCompare) > 0 Then
' PartOfWSName

foundSheet = ws.Name
Exit For
End If
Next ws

If foundSheet <> "*" Then
MsgBox "Found as sheet: " & foundSheet
Else
MsgBox "Not found as a sheet name."
End If

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
if the sheet name contains the active cell value it will find it
Using your example where the Active Cell is "227017.0.6230295.4.1" and the Sheet name is "6230295.4.1", the sheet name will never contain the active cell value. Do you mean "if the cell value contains the sheet name"?
 
Upvote 0
The active cell is dynamic, so that is one example where the sheet name contains part of the active cell but not all of it but it doesn't find it. Does that make sense?

Another example that DOES find the sheet is this: Active Cell is 557 and Sheet Name is SAIC 000557.
 
Upvote 0
It looks like sometimes the cell value contains the sheet name and sometimes the sheet name contains the cell value. Is this correct?
 
Upvote 0
I see what you are saying above... All or part of the active cell is in the sheet name. The active cell is what I have to search by to find the correct sheet because I will be searching that sheet for more items.
 
Upvote 0
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,177
Members
452,615
Latest member
bogeys2birdies

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