Q:

Excel-vba: Get the selected cell in a cell formula using a user defined function (UDF)

I've tried an obvious code, but it does not work.
Function SelectedRange(Optional ShiftRow As Long = 0, Optional ShiftColumn As Long = 0) As Range
    Set SelectedRange = Selection.Offset(ShiftRow, ShiftColumn)
End Function

The output is always the value of the cell with the formula (more or less the ShiftRow and the ShiftColumn) even after that I select other cells and recalculate the whole sheet manually.
What I did wrong?

A:

Addendum to @Gary's Student's answer, based on comments on question: when you click on a different cell in the workbook this code will find any cells with SelectedRange in the Formula, and Calculate those cells:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim rTMP As Range, sTMP As String
    Set rTMP = Me.Cells.Find("SelectedRange", Me.Cells(1, 1), xlFormulas, xlPart)
    If Not rTMP Is Nothing Then
        sTMP = rTMP.Address
        While Not rTMP Is Nothing
            rTMP.Calculate
            Set rTMP = Me.Cells.FindNext
            If rTMP.Address = sTMP Then Set rTMP = Nothing
        Wend
    End If
End Sub

