How to execute this function, matching 1 condition & performing this vba on a particular sheet.

In a Range of cells -
if value is 1, then perform this vba code in sheet1
if value is 2, then perform this vba code in sheet 2


Function HighestValue(r As String, rng As Range) As Double
Dim x, i&, dv#
x = Intersect(rng.Parent.UsedRange, rng).Value
For i = 1 To UBound(x)
If InStr(x(i, 1), r) Then If x(i, 2) > dv Then dv = x(i, 2)
Next
HighestValue = dv
End Function