PC Review


Reply
Thread Tools Rate Thread

Declaring Range

 
 
fi.or.jp.de
Guest
Posts: n/a
 
      8th May 2010
Hi All,

Is there any option to declare a range publicly.

I have more than 10 to 15 modules

I need to set the Rng as Range

i.e., set Rng = sheets("Sheet1").Range("A:A")
set Rng1 = Sheets("sheet1").Range("K:K")

.....So on..

I have to do, in each module i need to set the Rng or Rng1 or Rng2
etc....

Can i public declare or set the Ranges. so that I can use in any
module.

Please let me know, how can i achieve this.

Thanks in advance.
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      8th May 2010
Yes.

I like to use this technique.

I'll dedicate a General module that contains these public variables.

Then inside this General module, I'll use:

Option Explicit
Public Rng as Range

But since these variables can lose their contents, I'll have a couple more items
to this module.

One is a flag variable and one is a procedure that re-initializes these
variables (just in case).

Option Explicit
Public Rng as Range
Public VarsAreInitialized as Boolean 'my flag variable

Sub InitializeTheVariables()
VarsAreInitialized = true 'the flag that keeps track

'your code for setting Vars
Set Rng = sheets("Sheet1").Range("A:A")

End Sub

============
Now in any old procedure, I can use that variable -- but I'll check first.


if varsareinitialized = false then
call InitializeTheVariables
end if
msgbox Rng.address(external:=true)

==================
All that said, unless that variable always points to the same stuff (or value or
...), it's usually better practice to declare and assign the variables in the
routine that needs them.

You may want to look at VBA's help for "scope and visibility" for more info.



fi.or.jp.de wrote:

> Hi All,
>
> Is there any option to declare a range publicly.
>
> I have more than 10 to 15 modules
>
> I need to set the Rng as Range
>
> i.e., set Rng = sheets("Sheet1").Range("A:A")
> set Rng1 = Sheets("sheet1").Range("K:K")
>
> ....So on..
>
> I have to do, in each module i need to set the Rng or Rng1 or Rng2
> etc....
>
> Can i public declare or set the Ranges. so that I can use in any
> module.
>
> Please let me know, how can i achieve this.
>
> Thanks in advance.


--

Dave Peterson
 
Reply With Quote
 
fi.or.jp.de
Guest
Posts: n/a
 
      8th May 2010
Thanks dave

On May 8, 5:13*pm, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> Yes.
>
> I like to use this technique.
>
> I'll dedicate a General module that contains these public variables.
>
> Then inside this General module, I'll use:
>
> Option Explicit
> Public Rng as Range
>
> But since these variables can lose their contents, I'll have a couple more items
> to this module.
>
> One is a flag variable and one is a procedure that re-initializes these
> variables (just in case).
>
> Option Explicit
> Public Rng as Range
> Public VarsAreInitialized as Boolean 'my flag variable
>
> Sub InitializeTheVariables()
> * * VarsAreInitialized = true 'the flag that keeps track
>
> * * 'your code for setting Vars
> * * Set Rng = sheets("Sheet1").Range("A:A")
>
> End Sub
>
> ============
> Now in any old procedure, I can use that variable -- but I'll check first..
>
> if varsareinitialized = false then
> * * call InitializeTheVariables
> end if
> msgbox Rng.address(external:=true)
>
> ==================
> All that said, unless that variable always points to the same stuff (or value or
> * ...), it's usually better practice to declare and assign the variables in the
> routine that needs them.
>
> You may want to look at VBA's help for "scope and visibility" for more info.
>
>
>
>
>
> fi.or.jp.de wrote:
> > Hi All,

>
> > Is there any option to declare a range publicly.

>
> > I have more than 10 to 15 modules

>
> > I need to set the Rng as Range

>
> > i.e., set Rng = sheets("Sheet1").Range("A:A")
> > * * * *set Rng1 = Sheets("sheet1").Range("K:K")

>
> > ....So on..

>
> > I have to do, in each module i need to set the Rng or Rng1 or Rng2
> > etc....

>
> > Can i public declare or set the Ranges. so that I can use in any
> > module.

>
> > Please let me know, how can i achieve this.

>
> > Thanks in advance.

>
> --
>
> Dave Peterson


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring a variable as a range in another worksheet peturg@gmail.com Microsoft Excel Programming 5 8th Apr 2007 05:46 AM
Declaring this API in C#? (C++ example) =?Utf-8?B?U3BlY3RyZQ==?= Microsoft C# .NET 1 29th Mar 2006 05:07 PM
Declaring a Public variable as a Range and its lifetime John Wirt Microsoft Excel Programming 8 23rd Jan 2005 06:40 AM
Declaring a Range =?Utf-8?B?TWlrZXltYXk=?= Microsoft Excel Programming 1 2nd Nov 2004 04:22 PM
Declaring a Range Object pooja Microsoft Excel Programming 13 24th May 2004 04:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:35 PM.