How to retrieve cell addresses which call specific function
I need to find out cell addresses which have called a specific function.
If开发者_JS百科 my function is MyFunction (arg1, arg2), I should be able to find the cell addreses using name "MyFunction".
Please help me to find out what would be the most efficient way to do this.
Thank You
I asked the same question, but worded differently so I didn't find this one when I searched.
The interesting point is that the answer I got is, I think, better than the looping one for two reasons:
- Faster - no looping. Just use Application.Caller
- Works if your function is called from more than one cell
You can loop through a range of cells, looking for that particular function:
Dim name as String
Dim searchRange as Range
Dim row as Integer
Dim col as Integer
name = "MyFunction" ''// for example
Set searchRange = Range("A1:P:50") ''// for example
For row = 1 to searchRange.Rows.Count
For col = 1 to searchRange.Columns.Count
If Left(searchRange.Cells(row, col).Formula, Len(name)) = name Then
''// do something with this cell
End If
Next col
Next row
精彩评论