I am relatively new to VBA in excel. I would like to write a custom function that takes a range defined by the user as input and then searches for a particular word within that range. So far, the following code works, but it only searches in the predefined range "a2:g2", but I would want something that would change to "a3:g3", etc as the user fills down:
Function findme()
With Worksheets("Filtered").Range("a2:g2")
Set c = .Find("XXXX", LookIn:=xlValues)
If Not c Is Nothing Then
findme = "Match Found"
Else: findme = "No match"
End If
End With
I thought this should work, but it does not. It returns "VALUE"
Function findme(myrange as range)
With Worksheets("Filtered").Range(myrange)
Set c = .Find("XXXX", LookIn:=xlValues)
If Not c Is Nothing Then
findme = "Match Found"
Else: findme = "No match"
End If
End With