constants

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top