ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA returning a cell address (https://www.excelbanter.com/excel-programming/278368-vba-returning-cell-address.html)

[email protected]

VBA returning a cell address
 
I am trying to write VBA code to return the cell address on one
worksheet within a workbook to another worksheet. The result will be
in the simple formula, for example "='Sheet1'!B3" and this formula
will be on Sheet 2.

I have a macro that is giving the cell on Sheet1 a range name,
"FirstCell" in this case, because the cell I want is a moving target.
I have another piece of macro code which is the following,
Range("D5").Formula = "='Sheet1!" & Range("FirstCell").Address. This
is doing a great job of putting the formula ='Sheet1'!$B$3 on Sheet 2
in cell D5. The problem is that it is an absolute reference and I
want a relative reference. How can I change this result so I will
have the formula ='Sheet1'!B3.

Thanks, Ken

J.E. McGimpsey

VBA returning a cell address
 
Take a look at Address in VBA Help:

One way:

Range("D5").Formula = "=Sheet1!" & _
Range("FirstCell").Address(False, False)


In article ,
wrote:

I am trying to write VBA code to return the cell address on one
worksheet within a workbook to another worksheet. The result will be
in the simple formula, for example "='Sheet1'!B3" and this formula
will be on Sheet 2.

I have a macro that is giving the cell on Sheet1 a range name,
"FirstCell" in this case, because the cell I want is a moving target.
I have another piece of macro code which is the following,
Range("D5").Formula = "='Sheet1!" & Range("FirstCell").Address. This
is doing a great job of putting the formula ='Sheet1'!$B$3 on Sheet 2
in cell D5. The problem is that it is an absolute reference and I
want a relative reference. How can I change this result so I will
have the formula ='Sheet1'!B3.

Thanks, Ken


Vasant Nanavati[_2_]

VBA returning a cell address
 
Hi Ken:

Range("FirstCell").Address(False,False)

Regards,

Vasant.

wrote in message
om...
I am trying to write VBA code to return the cell address on one
worksheet within a workbook to another worksheet. The result will be
in the simple formula, for example "='Sheet1'!B3" and this formula
will be on Sheet 2.

I have a macro that is giving the cell on Sheet1 a range name,
"FirstCell" in this case, because the cell I want is a moving target.
I have another piece of macro code which is the following,
Range("D5").Formula = "='Sheet1!" & Range("FirstCell").Address. This
is doing a great job of putting the formula ='Sheet1'!$B$3 on Sheet 2
in cell D5. The problem is that it is an absolute reference and I
want a relative reference. How can I change this result so I will
have the formula ='Sheet1'!B3.

Thanks, Ken




Alan Beban[_3_]

VBA returning a cell address
 
Use Range("FirstCell").Address(0,0)

Alan Beban

wrote:
I am trying to write VBA code to return the cell address on one
worksheet within a workbook to another worksheet. The result will be
in the simple formula, for example "='Sheet1'!B3" and this formula
will be on Sheet 2.

I have a macro that is giving the cell on Sheet1 a range name,
"FirstCell" in this case, because the cell I want is a moving target.
I have another piece of macro code which is the following,
Range("D5").Formula = "='Sheet1!" & Range("FirstCell").Address. This
is doing a great job of putting the formula ='Sheet1'!$B$3 on Sheet 2
in cell D5. The problem is that it is an absolute reference and I
want a relative reference. How can I change this result so I will
have the formula ='Sheet1'!B3.

Thanks, Ken




All times are GMT +1. The time now is 11:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com