Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get address of cell which calls a VBA Functions in a Excel sheet

Tags:

Is there a function to get the address of a cell which call a VBA function ?

I used "Application.ActiveCell.Address" , but found that this method is not a correct way to get the address of calling cell.

e.g: If we have excel sheet with saved VBA functions, Once you reopen the sheet, the above method will not work.

please help

nimo

like image 321
Nimo Avatar asked Feb 13 '10 21:02

Nimo


People also ask

How do I find the cell address in Excel VBA?

It is called “Active Cell” in VBA. If your active cell not visible in your window, then look at the name box. The name is usually the row character followed by the column number, such as cell A1. read more, it will show you the active cell address.

How do I find the address of a cell in Excel?

The Excel ADDRESS function returns the address for a cell based on a given row and column number. For example, =ADDRESS(1,1) returns $A$1. ADDRESS can return an address in relative, mixed, or absolute format, and can be used to construct a cell reference inside a formula.

How are cells referenced in VBA?

If the Excel VBA Range object you want to refer to is a single cell, the syntax is simply “Range(“Cell”)”. For example, if you want to make reference to a single cell, such as A1, type “Range(“A1″)”.

How do I use a range address in Excel VBA?

Now you need to enter the row size and column size. Type a starting parenthesis and enter the number to define the row size and then a number to define the column size. In the end, add “. Select” to tell VBA to select the range, and when you run this code, it will select the range.


1 Answers

You can use Application.Caller, but you would probably be best to pass the cell to the function.

   With Application.Caller         CallerRows = .Rows.Count         CallerCols = .Columns.Count         CallerAddr = .Address    End With 

See: http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx

To pass the cell:

 =SomeFunction(A1) 

Where the code has:

SomeFunction(r) 
like image 68
Fionnuala Avatar answered Sep 25 '22 16:09

Fionnuala