Mackeral
Board Regular
- Joined
- Mar 7, 2015
- Messages
- 249
- Office Version
- 365
- Platform
- Windows
You can see the comments I've made to make this routine work now. It worked in it's original form 2 or 3 days ago.
The issue is that it use to (and should basically) work on a non-Active sheet.
To make it work with now, I had to change the code to make the sheet with the data to be searched Active.
The issue is that it use to (and should basically) work on a non-Active sheet.
To make it work with now, I had to change the code to make the sheet with the data to be searched Active.
VBA Code:
Function Find_String(Sheet_Spec, _
Rng, Look_For, _
Optional Answer_Row, Optional Answer_Col, _
Optional LookAt As Look_Ats = xlWhole, _
Optional Case_Arg As Boolean = False) As Boolean
' Lookup a String in a Sheet and return its address in ROW and COL.
' Note: The Sheet must be in the currently opened Workbook.
' Note: LookAt can have values "xlPart" or "xlWhole".
' 12/22/10 Replaced Find_Sub. WML
' 12/22/10 Replaced xlLookAts Enum. WML
' 7/24/15 Made all args after Look_For optional. WML
' 3/28/18 Added call to "Make_Range_Special". WML
' 9/4/19 Changed "Case_Arg" option to False. WML
' 1/15/20 Added check to see if finding the same row, in which case it's an error. WML
' 5/12/20 Changed code because of Microsoft change. WML
Dim SHEET As Worksheet
Prog = "Find_String"
Curr_Sheet = ActiveSheet.Name ' <-- Really?
Call Sheet_Arg(Sheet_Spec, SHEET, Sheet_Name)
SHEET.Activate ' < And this too?
With SHEET.Range(Rng)
Set HOLD = Selection.Find(What:=Look_For, _
After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
End With
If HOLD Is Nothing Then
Find_String = False
Else
' Extra test to be sure
Answer_Row = HOLD.Row
Answer_Col = HOLD.Column
Find_String = ( Look_For = Cells(Answer_Row, Answer_Col))
End If
Sheets(Curr_Sheet).Activate ' <-- And this too.
End Function ' Find_String