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
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