I'm trying to create a function that looks for a value in a given range of cells, but it is not being executed. It should return the cell where the value is found.
Function searchInRange(where As Range, what As String) As Range
For Each c In where.Cells
Debug.Print (c.Value)
If c.Value = what Then
searchInRange = c
End If
Next c
End Function
I'm calling it from a submodule, but it is not executed. If I go to debug the debugger just jumps to the next statement without entering in the function. I don't understand why
EDIT
As many people suggested, I'm posting the module that calls the functions. It is a button click function. The file and sheet are correctly selected. I know this because the last sentence (PE_Sheet.activate) works correctly. Regards.
Private Sub CommandButton1_Click()
Dim PE_File As Workbook
Dim PE_Sheet As Worksheet
Dim cell As Range
Set PE_File = Workbooks(getSelectedWorkbook())
Set PE_Sheet = PE_File.Worksheets("Monitored")
Unload UserForm1
searchAlarmFilter PE_Sheet.Range("A:A"), "5184"
PE_Sheet.Activate
End Sub
exit foras you risk overwriting earlier results