Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default only 1 time declaring variables

Hello,

question on how to declare variables.

I have something simples like this

Sub Test ()

Dim H1 As Integer

H1 = Range("B6").Value

MsgBox ("Test number: " & H1 )

End Sub

Is there an easy way to use the "H1" value without again having to declare
it?

Sub Test2 ()

MsgBox ("Test 2 number : " & H1 )

End Sub
--------------------------
thanks for the help again

Swingleft

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default only 1 time declaring variables

Hi,

Am Fri, 12 Aug 2011 20:45:54 +0200 schrieb Swingleft:

Is there an easy way to use the "H1" value without again having to declare
it?


you have to declare H1 as Public:

Option Explicit
Public H1 As Integer

Sub Test()
H1 = Range("B6").Value
MsgBox ("Test number: " & H1)
End Sub

Sub Test2()
MsgBox ("Test 2 number : " & H1)
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default only 1 time declaring variables

Thanks...

"Claus Busch" schreef in bericht ...

Hi,

Am Fri, 12 Aug 2011 20:45:54 +0200 schrieb Swingleft:

Is there an easy way to use the "H1" value without again having to declare
it?


you have to declare H1 as Public:

Option Explicit
Public H1 As Integer

Sub Test()
H1 = Range("B6").Value
MsgBox ("Test number: " & H1)
End Sub

Sub Test2()
MsgBox ("Test 2 number : " & H1)
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default only 1 time declaring variables

Hi,

Am Fri, 12 Aug 2011 20:52:42 +0200 schrieb Claus Busch:

Option Explicit
Public H1 As Integer


but you have to run Test() first to initialize H1 or you have to
initialize H1 in Test2() too.


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default only 1 time declaring variables

On 8/12/2011 11:45 AM, Swingleft wrote:
Hello,
question on how to declare variables.
I have something simples like this
Sub Test ()
Dim H1 As Integer
H1 = Range("B6").Value
MsgBox ("Test number: " & H1 )
End Sub
Is there an easy way to use the "H1" value without again having to
declare it?
Sub Test2 ()
MsgBox ("Test 2 number : " & H1 )
End Sub
--------------------------
thanks for the help again
Swingleft


Variable scope:

http://support.microsoft.com/kb/141693
http://www.ozgrid.com/VBA/variable-scope-lifetime.htm





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default only 1 time declaring variables

"Mike S" schreef in bericht ...

On 8/12/2011 11:45 AM, Swingleft wrote:
Hello,
question on how to declare variables.
I have something simples like this
Sub Test ()
Dim H1 As Integer
H1 = Range("B6").Value
MsgBox ("Test number: " & H1 )
End Sub
Is there an easy way to use the "H1" value without again having to
declare it?
Sub Test2 ()
MsgBox ("Test 2 number : " & H1 )
End Sub
--------------------------
thanks for the help again
Swingleft


Variable scope:

http://support.microsoft.com/kb/141693
http://www.ozgrid.com/VBA/variable-scope-lifetime.htm

Thanks Mike.. these sites are very usefull
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default only 1 time declaring variables

basically we need variable..............

please find the below links for more information about variable

http://www.functionx.com/vbaexcel/Lesson05.htm
http://www.ozgrid.com/VBA/variables.htm

and your code we need variable but don't need to declare

Sub Test2 ()
x = range("H1").value
MsgBox ("Test 2 number : " & x )

End Sub

On Aug 12, 11:45*pm, "Swingleft" wrote:
Hello,

question on how to declare variables.

I have something simples like this

Sub Test ()

Dim H1 As Integer

H1 = Range("B6").Value

MsgBox ("Test number: " & H1 )

End Sub

Is there an easy way to use the "H1" value without again having to declare
it?

Sub Test2 ()

MsgBox ("Test 2 number : " & H1 )

End Sub
--------------------------
thanks for the help again

Swingleft


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
Declaring Variables BlairH Excel Programming 3 June 4th 10 03:04 PM
Declaring Variables Twice? Chad[_12_] Excel Programming 2 May 19th 09 11:48 PM
Declaring variables Mike Excel Programming 4 November 28th 05 07:05 PM
DEclaring variables Pedro Excel Programming 1 November 13th 03 05:02 PM
Declaring variables Pedro Excel Programming 1 November 13th 03 03:32 PM


All times are GMT +1. The time now is 04:31 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"