I have made a UDF that works on a single sheet. The problem occurs with multiple sheets. If I have the formula on multiple sheets, and if I (re-)load it on one sheet, it changes the output in ALL other sheets, too.
Why does this happen? I am not using ActiveWorksheet or Active Cell or similar.
Function customreturn(security As Range, datacheck As Range) As Variant
Dim row_num As Integer
Dim row_num2 As Integer
Dim price1 As Double
Dim price2 As Double
Dim perfo As Double
Dim blank_end As Boolean
row_num = security.Row
col_num = security.Column
row_num2 = row_num + 1
col_num2 = datacheck.Column
If WorksheetFunction.IsError(datacheck.Value) = True Then
customreturn = "No data"
Else
price1 = Cells(row_num, col_num).Value
Do While WorksheetFunction.IsError(Cells(row_num2, col_num2).Value) = True
row_num2 = row_num2 + 1
Loop
price2 = Cells(row_num2, col_num).Value
perfo = price1 / price2 - 1
customreturn = perfo
End If
End Function