tags:

views:

24

answers:

1

Hi,

I need to find out cell addresses which has called a specific function,

If 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

+1  A: 

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
e.James
+1 for the good answer and for fooling Markdown into properly handling VBA comments :-)
Adam Bernier
Thank You for the answer, thus I found Excel Find() which would be more efficient than a loop.ref: http://www.ozgrid.com/VBA/find-method.htm
nimo
@nimo: That's a good find. Why not post it as an answer, and then mark it as accepted? There's nothing wrong with answering your own question `:)`
e.James
@Adam Bernier: Thank you. Those single-quote VBA comments are tricky! `:)`
e.James