I'm working on a bigger Excel Macro, but have simplified my code a bit and found what my issue is. In the if statement below, I can change the rng to a cell that makes the statement true, and it works fine. But if I change it to a cell (or a cell within a range) that will return false, it returns the #value error. I'm pretty new to VBA, so what am I doing wrong?
Function count_same(column As Range, row As Range)
Dim rng As Range
Dim cell As Range
Dim result As Long
result = 0
Set rng = Worksheets("Install together 2").Range("f10")
For Each cell In rng.Cells
If WorksheetFunction.IsNumber(WorksheetFunction.Search(row.Value, cell.Value)) Then
result = result + 1
End If
Next cell
count_same = result
End Function
if instr(1,cell,row) > 0 then
– ZerkOn Error Resume Next
should be avoided unless absolutely neccesary. – Brandon Barney