ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Define Name use in Macros (https://www.excelbanter.com/excel-discussion-misc-queries/35343-define-name-use-macros.html)

Bill Christian

Define Name use in Macros
 
I am not sure how or if you can use the Define Name function in a worksheet
to assign a value in an Macro. I am using the command below to assign a value
in the worksheet in the macro. However the user might make changes to the
worksheet that makes this method invalid. If I use the Define Name function
in excel and create a Name can I then us it to assign a value?

Set Total_Assets = Sheets("Balance Sheet").Range("H55")


Jim Rech

You should definitely assign a name (Ctrl-F3) to this cell and all ranges
your macros used, in case you or your users insert rows, etc.

Set Total_Assets = Sheets("Balance Sheet").Range("TotAssets")


--
Jim
"Bill Christian" <Bill wrote in message
...
|I am not sure how or if you can use the Define Name function in a worksheet
| to assign a value in an Macro. I am using the command below to assign a
value
| in the worksheet in the macro. However the user might make changes to the
| worksheet that makes this method invalid. If I use the Define Name
function
| in excel and create a Name can I then us it to assign a value?
|
| Set Total_Assets = Sheets("Balance Sheet").Range("H55")
|



KL

Hi Bill,

Yes, you can and the sintax is identical:

Set Total_Assets = Sheets("Balance Sheet").Range("MyDefinedName")


Regards,
KL



"Bill Christian" <Bill wrote in message
...
I am not sure how or if you can use the Define Name function in a worksheet
to assign a value in an Macro. I am using the command below to assign a
value
in the worksheet in the macro. However the user might make changes to the
worksheet that makes this method invalid. If I use the Define Name
function
in excel and create a Name can I then us it to assign a value?

Set Total_Assets = Sheets("Balance Sheet").Range("H55")




Bill Christian

Thanks to Jim & KL. My macro is now more readable and bullet proof.

"KL" wrote:

Hi Bill,

Yes, you can and the sintax is identical:

Set Total_Assets = Sheets("Balance Sheet").Range("MyDefinedName")


Regards,
KL



"Bill Christian" <Bill wrote in message
...
I am not sure how or if you can use the Define Name function in a worksheet
to assign a value in an Macro. I am using the command below to assign a
value
in the worksheet in the macro. However the user might make changes to the
worksheet that makes this method invalid. If I use the Define Name
function
in excel and create a Name can I then us it to assign a value?

Set Total_Assets = Sheets("Balance Sheet").Range("H55")






All times are GMT +1. The time now is 02:28 PM.

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