Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get worksheet and cell that the current VBA function is returning to?

Tags:

excel

vba

Is there a variable anywhere that gives the worksheet and cell that will recieve the result of a custom VBA function?

For example, if in A!B1 the formula is =MyCustomFunc() in my code:

public function MyCustomFunc()
    'what can I call here to get the values "A" and "B1"?
end function
like image 895
Jake Avatar asked Apr 27 '12 02:04

Jake


1 Answers

Is this what you are trying?

Option Explicit

Public Function MyCustomFunc()
    '~~> Judicious use of 'Volatile' is advised.
    '~~> This will be called everytime the sheet is recalculated
    Application.Volatile

    MsgBox Application.Caller.Parent.Name & ", " & Application.Caller.Address
End Function
like image 98
Siddharth Rout Avatar answered Oct 26 '22 06:10

Siddharth Rout