All your function does is return the lineID if it's found; I'd have thought it would return the line number. Either way, the code is looking on the active worksheet, not in dataSheetName.
I would code it like this to return the row number:
Sub EG()
Dim lineID As Long
lineID = 42
If findCoordinatesForX(lineID, Worksheets("Bob")) <> 0 Then
' whatever
Else
' whatever else
End If
End Sub
Function findCoordinatesForX(lineID As Long, wks As Worksheet) As Long
Dim cell As Range
Set cell = wks.Range("A:A").Find(What:=lineID, LookIn:=xlValues, LookAt:=xlWhole)
If Not cell Is Nothing Then findCoordinatesForX = cell.Row
End Function
Or this to just return True if the value is found:
Sub EG()
Dim lineID As Long
lineID = 42
If findCoordinatesForX(lineID, Worksheets("Bob")) Then
' whatever
Else
' whatever else
End If
End Sub
Function findCoordinatesForX(lineID As Long, wks As Worksheet) As Boolean
Dim cell As Range
Set cell = wks.Range("A:A").Find(What:=lineID, LookIn:=xlValues, LookAt:=xlWhole)
findCoordinatesForX = Not cell Is Nothing
End Function
Bookmarks