ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   constants (https://www.excelbanter.com/excel-programming/309438-constants.html)

alekm

constants
 
Hi, I'm using Worksheet_SelectionChange event in my workbook. On the very
begining of procedure I have some values initialized that I want to be
constants like this:

Dim x, y As String
x = "C1"
y = "H3"
...

I guess it's bad solution to have them initialized in the event procedure
because this way they get initialized every time event occurs. Where can I
put them to be initialized once and visible for Worksheet_SelectionChange
and other subs?
Shall I also set them at nothing and where when exiting workbook?
Thanx
alekmil

Tom Ogilvy

constants
 
There shouldn't be any major penalty with initializing then in the Change
event since that is the only place they are used. When the change event
ends, they are destroyed, so there is no requirement to explicitly do
anything else to them.

Also, note that when you declare the type for a variable in VBA, you need to
declare the type for each variable.

Dim x, y as String

x is a variant
y is a string

Dim x as String, y as String
x is a string
y is a string

--
Regards,
Tom Ogilvy

"alekm" wrote in message
...
Hi, I'm using Worksheet_SelectionChange event in my workbook. On the very
begining of procedure I have some values initialized that I want to be
constants like this:

Dim x, y As String
x = "C1"
y = "H3"
...

I guess it's bad solution to have them initialized in the event procedure
because this way they get initialized every time event occurs. Where can I
put them to be initialized once and visible for Worksheet_SelectionChange
and other subs?
Shall I also set them at nothing and where when exiting workbook?
Thanx
alekmil





All times are GMT +1. The time now is 04:12 AM.

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