ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Variables initiation (https://www.excelbanter.com/excel-programming/437706-variables-initiation.html)

Alberto Ast[_2_]

Variables initiation
 
I need to initiate some variables...

to initiate the variables within a form I use

Private Sub UserForm_Initialize()
......
End Sub

How do I do it within a module?

Ryan H

Variables initiation
 
You declare variables many ways. Check this link out by Chip Pearson. It
helped me when I was learning.

Hope this helps! If so, let me know, click "YES" below.
--
Cheers,
Ryan


"Alberto Ast" wrote:

I need to initiate some variables...

to initiate the variables within a form I use

Private Sub UserForm_Initialize()
......
End Sub

How do I do it within a module?


Ryan H

Variables initiation
 
I guess it would help if I gave you the link, sorry.

http://www.cpearson.com/excel/DeclaringVariables.aspx
--
Cheers,
Ryan


"Ryan H" wrote:

You declare variables many ways. Check this link out by Chip Pearson. It
helped me when I was learning.

Hope this helps! If so, let me know, click "YES" below.
--
Cheers,
Ryan


"Alberto Ast" wrote:

I need to initiate some variables...

to initiate the variables within a form I use

Private Sub UserForm_Initialize()
......
End Sub

How do I do it within a module?


Alberto Ast[_2_]

Variables initiation
 
Thanks Ryan..

Somehow I can not see this post when I list all those I have had some
activities but Mike H have forward me the link and I was able to see the
post... any way... pearson link showed me how to declare variables but how do
I gave them an initial value different than its default value?

"Ryan H" wrote:

I guess it would help if I gave you the link, sorry.

http://www.cpearson.com/excel/DeclaringVariables.aspx
--
Cheers,
Ryan


"Ryan H" wrote:

You declare variables many ways. Check this link out by Chip Pearson. It
helped me when I was learning.

Hope this helps! If so, let me know, click "YES" below.
--
Cheers,
Ryan


"Alberto Ast" wrote:

I need to initiate some variables...

to initiate the variables within a form I use

Private Sub UserForm_Initialize()
......
End Sub

How do I do it within a module?


Mike H

Variables initiation
 
Hi,

In a macro the variables are 'generally' initialised at the top of the code:-

Sub MyMacro()
Dim x as Long
Dim MyRange as range

etc.

By default when initialised they ere empty and you then have to assign a value

Sub MyMacro()
Dim x as Long
Dim MyRange as range
x=999
set MyRange=range("A1:A1000")

Mike

"Alberto Ast" wrote:

Thanks Ryan..

Somehow I can not see this post when I list all those I have had some
activities but Mike H have forward me the link and I was able to see the
post... any way... pearson link showed me how to declare variables but how do
I gave them an initial value different than its default value?

"Ryan H" wrote:

I guess it would help if I gave you the link, sorry.

http://www.cpearson.com/excel/DeclaringVariables.aspx
--
Cheers,
Ryan


"Ryan H" wrote:

You declare variables many ways. Check this link out by Chip Pearson. It
helped me when I was learning.

Hope this helps! If so, let me know, click "YES" below.
--
Cheers,
Ryan


"Alberto Ast" wrote:

I need to initiate some variables...

to initiate the variables within a form I use

Private Sub UserForm_Initialize()
......
End Sub

How do I do it within a module?


Alberto Ast[_2_]

Variables initiation
 
I have several macros than while runing the program I can execute one or the
other but need a public variable to be set up to a certain value. Then the
variable keep changing during the execution of several macros. If I do not
initialize my variable to a specific value my macros might fail depending on
the order the macros are selected to be excecuted. This is why I need to
initilize my variable before any macro is excecuted so regardless or the
sequence my progam will work ok.

my variable is like this
Public wHide, wHide2, wHide3 As Worksheet

and I assign different worksheets to the variables during my progams and
then I make them visible tru o false... but if I execute the

Sheets(wHide).Visible = False
before it is assigned to a sheet then my progma fail so I want to initialy
ie to any sheet so it will not fail

when I do
Private Sub UserForm_Initialize()
......
End Sub

in a user form it initialize some of my variables and I do nto need to run
this Sub it just does it... how can I do the initialization in a module.

"Mike H" wrote:

Hi,

In a macro the variables are 'generally' initialised at the top of the code:-

Sub MyMacro()
Dim x as Long
Dim MyRange as range

etc.

By default when initialised they ere empty and you then have to assign a value

Sub MyMacro()
Dim x as Long
Dim MyRange as range
x=999
set MyRange=range("A1:A1000")

Mike

"Alberto Ast" wrote:

Thanks Ryan..

Somehow I can not see this post when I list all those I have had some
activities but Mike H have forward me the link and I was able to see the
post... any way... pearson link showed me how to declare variables but how do
I gave them an initial value different than its default value?

"Ryan H" wrote:

I guess it would help if I gave you the link, sorry.

http://www.cpearson.com/excel/DeclaringVariables.aspx
--
Cheers,
Ryan


"Ryan H" wrote:

You declare variables many ways. Check this link out by Chip Pearson. It
helped me when I was learning.

Hope this helps! If so, let me know, click "YES" below.
--
Cheers,
Ryan


"Alberto Ast" wrote:

I need to initiate some variables...

to initiate the variables within a form I use

Private Sub UserForm_Initialize()
......
End Sub

How do I do it within a module?


Ryan H

Variables initiation
 
All userforms run an Intialize Event when the userform is first loaded into
memory. If you have code in it then the code will be ran, if not then it
continues on. You can set each of your worksheet variables at the beginning
of each macro like this

Set wHide = Sheets("Sheet1")

I did notice one thing in your previous post that may be giving you some
problems.

You use this to declare your worksheets. This should be in a standard
module. Which is correct!

Public wHide, wHide2, wHide3 As Worksheet

But using this code to use your publically declared worksheets is incorrect.

Sheets(wHide).Visible = False
You are using wHide as a string not as a worksheet.

You should use:

wHide.Visible = False

or

Sheets(wHide.Name).Visible = False

--
Cheers,
Ryan


"Alberto Ast" wrote:

I have several macros than while runing the program I can execute one or the
other but need a public variable to be set up to a certain value. Then the
variable keep changing during the execution of several macros. If I do not
initialize my variable to a specific value my macros might fail depending on
the order the macros are selected to be excecuted. This is why I need to
initilize my variable before any macro is excecuted so regardless or the
sequence my progam will work ok.

my variable is like this
Public wHide, wHide2, wHide3 As Worksheet

and I assign different worksheets to the variables during my progams and
then I make them visible tru o false... but if I execute the

Sheets(wHide).Visible = False
before it is assigned to a sheet then my progma fail so I want to initialy
ie to any sheet so it will not fail

when I do
Private Sub UserForm_Initialize()
......
End Sub

in a user form it initialize some of my variables and I do nto need to run
this Sub it just does it... how can I do the initialization in a module.

"Mike H" wrote:

Hi,

In a macro the variables are 'generally' initialised at the top of the code:-

Sub MyMacro()
Dim x as Long
Dim MyRange as range

etc.

By default when initialised they ere empty and you then have to assign a value

Sub MyMacro()
Dim x as Long
Dim MyRange as range
x=999
set MyRange=range("A1:A1000")

Mike

"Alberto Ast" wrote:

Thanks Ryan..

Somehow I can not see this post when I list all those I have had some
activities but Mike H have forward me the link and I was able to see the
post... any way... pearson link showed me how to declare variables but how do
I gave them an initial value different than its default value?

"Ryan H" wrote:

I guess it would help if I gave you the link, sorry.

http://www.cpearson.com/excel/DeclaringVariables.aspx
--
Cheers,
Ryan


"Ryan H" wrote:

You declare variables many ways. Check this link out by Chip Pearson. It
helped me when I was learning.

Hope this helps! If so, let me know, click "YES" below.
--
Cheers,
Ryan


"Alberto Ast" wrote:

I need to initiate some variables...

to initiate the variables within a form I use

Private Sub UserForm_Initialize()
......
End Sub

How do I do it within a module?



All times are GMT +1. The time now is 10:46 AM.

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