Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.
Function FindExcelTab(ByVal CC As String, EmailType As String) As String
Dim FoundIt As Boolean
For Each WS In ActiveWorkbook.Worksheets
If Mid(WS.Name, 1, 3) <> "MC " And _
WS.Name <> "Main" And _
WS.Name <> "Final Report" Then
If EmailType <> "Liberty" Then
If Len(WS.Range("D2")) > 15 Then
If Left(Format(WS.Range("D2"), "#"), Len(Format(WS.Range("D2"), "#")) - 1) = Left(CC, Len(CC) - 1) Then
MsgBox ("Found " & WS.Name)
FoundIt = True
Exit For
End If
End If
Else
If WS.Range("E2") = CC Or InStr(1, WS.Range("E2"), CC) <> 0 Then
MsgBox ("Found " & WS.Name)
FoundIt = True
Exit For
End If
End If
End If
Next WS
If FoundIt Then
FindExcelTab = WS.Name
Else
FindExcelTab = ""
End If
End Function
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Join the community of 500,000 technology professionals and ask your questions.