ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I control the cell reference when naming a cell in a macro (https://www.excelbanter.com/excel-programming/389872-how-do-i-control-cell-reference-when-naming-cell-macro.html)

glenn

How do I control the cell reference when naming a cell in a macro
 
When recording a macro that creates or defines a range name for a cell, I can
programantically get to the cell I want, but the recorded macro adds a fixed
reference (see example below) that I'd like to control without using a
combination of numeric and string variables. I'd like to create the name
using an active cell reference. Is this possible?

ActiveWorkbook.Names.Add Name:="TOT", RefersToR1C1:="=PgrmPvtName!R4C38"

AKphidelt

How do I control the cell reference when naming a cell in a macro
 
Try



ActiveWorkbook.Names.Add Name:="TOT", RefersTo:="=" & ActiveCell.Address

"Glenn" wrote:

When recording a macro that creates or defines a range name for a cell, I can
programantically get to the cell I want, but the recorded macro adds a fixed
reference (see example below) that I'd like to control without using a
combination of numeric and string variables. I'd like to create the name
using an active cell reference. Is this possible?

ActiveWorkbook.Names.Add Name:="TOT", RefersToR1C1:="=PgrmPvtName!R4C38"


glenn

How do I control the cell reference when naming a cell in a ma
 
Worked great....
Thanks a whole bunch.

"AKphidelt" wrote:

Try



ActiveWorkbook.Names.Add Name:="TOT", RefersTo:="=" & ActiveCell.Address

"Glenn" wrote:

When recording a macro that creates or defines a range name for a cell, I can
programantically get to the cell I want, but the recorded macro adds a fixed
reference (see example below) that I'd like to control without using a
combination of numeric and string variables. I'd like to create the name
using an active cell reference. Is this possible?

ActiveWorkbook.Names.Add Name:="TOT", RefersToR1C1:="=PgrmPvtName!R4C38"



All times are GMT +1. The time now is 09:42 AM.

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