Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default 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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default 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?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default 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?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default 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?

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default 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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Storing variables in a macro and using those variables to performcalculations. [email protected] Excel Programming 3 December 10th 07 04:13 PM
Batch file initiation from Excel macro? Yarroll Excel Discussion (Misc queries) 1 October 13th 06 02:50 PM
excel - macro - automatic initiation of a macro at a pre-specified "system time" arunjoshi[_3_] Excel Programming 3 May 1st 04 09:42 AM
excel macro - macro initiation upon hitting the ener key arunjoshi[_2_] Excel Programming 1 April 28th 04 09:58 PM


All times are GMT +1. The time now is 07:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"