ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Excel cell formulas and VBA (https://www.excelbanter.com/excel-discussion-misc-queries/190330-excel-cell-formulas-vba.html)

bteddy

Excel cell formulas and VBA
 
Hello,
On a worksheet, in a cell, with in a formula I need to reference a global
variable set in a vba modual.

Example: = (a1+z13)*2.537/myvar

How is this done? What is the proper term for this? I tried searching on the
net, but found nothing.

Thank you for your time.

Gary''s Student

Excel cell formulas and VBA
 
Running something like:

Sub Macro1()
ActiveWorkbook.Names.Add Name:="myvar", RefersToR1C1:="=5678"
End Sub

will create and assign a value to a variable that can be used on the
worksheet.
--
Gary''s Student - gsnu200790


"bteddy" wrote:

Hello,
On a worksheet, in a cell, with in a formula I need to reference a global
variable set in a vba modual.

Example: = (a1+z13)*2.537/myvar

How is this done? What is the proper term for this? I tried searching on the
net, but found nothing.

Thank you for your time.


EricJohnson[_2_]

Excel cell formulas and VBA
 
A variation of this approach is to define the name through Insert - Names -
Define. Give it the name "myvar" and in the "Refers To" section at the
bottom of the window, type in 5678 and click on OK. You've now defined a
name, myvar, and given it a value.

Under macro control, you can do something like this:

Sub Updatemyvar(NewVal As Single)
ThisWorkbook.Names("myvar").Value = NewVal
End Sub

The previous post would be a convenient way to create and initialize the
name, if you didn't want to perform this task manually, as described above.

"Gary''s Student" wrote:

Running something like:

Sub Macro1()
ActiveWorkbook.Names.Add Name:="myvar", RefersToR1C1:="=5678"
End Sub

will create and assign a value to a variable that can be used on the
worksheet.
--
Gary''s Student - gsnu200790


"bteddy" wrote:

Hello,
On a worksheet, in a cell, with in a formula I need to reference a global
variable set in a vba modual.

Example: = (a1+z13)*2.537/myvar

How is this done? What is the proper term for this? I tried searching on the
net, but found nothing.

Thank you for your time.



All times are GMT +1. The time now is 10:25 PM.

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