ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Variable values (https://www.excelbanter.com/excel-programming/369512-variable-values.html)

Ed

Variable values
 
I've set up two macros "A" and "B" for use on a worksheet.

I assigned a value say 4 to a variable "v" in macro A.

I find that the value 4 does not carry over to a variable "v" in
macro B.

Is there a way to have the variables of macro A apply to all other
macros used with the worksheet?

Thanks,


Ed

Gary''s Student

Variable values
 
DIM the variable before the macros in the module:

DIM v
Sub a()
..
..
..
End Sub
Sub b()
..
..
..
End Sub
--
Gary''s Student


"Ed" wrote:

I've set up two macros "A" and "B" for use on a worksheet.

I assigned a value say 4 to a variable "v" in macro A.

I find that the value 4 does not carry over to a variable "v" in
macro B.

Is there a way to have the variables of macro A apply to all other
macros used with the worksheet?

Thanks,


Ed


Joerg

Variable values
 

"Ed" wrote in message
...
I've set up two macros "A" and "B" for use on a worksheet.

I assigned a value say 4 to a variable "v" in macro A.

I find that the value 4 does not carry over to a variable "v" in
macro B.

Is there a way to have the variables of macro A apply to all other
macros used with the worksheet?


If the macros are in one module: put a 'Dim v' statement at the beginning of
the module (in the General section). Your variable will be recognizes in all
macros (do not but a Dim v statement into any of your macros, this would
override the general declaration.

If macros are in separate modules, put a 'Public v' statement into the
general section of any module.

Joerg




All times are GMT +1. The time now is 01:43 PM.

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