Sub runme(x As Integer, sht As String, val As String) 'add 2 because of the extra 2 rows x = x + 2 If sht = "Actual" Then If val = "RS" Then If (! + B + x) = 0 Then Return Else tmp = "Actual!B" + x as String Return tmp End If End If End Sub ----- invoking it ----- Excel cell's value: =IF(D4=0," ",runme(D4,"Actual","RS"))