View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Stormy Stormy is offline
external usenet poster
 
Posts: 17
Default initialise declaration

Another method you might consider is "lazy initialization"...
Public rng_source, rng_x As Range

if TypeName(rng_source) = "Nothing" then Set rng_source = Range("B3:J11")
if TypeName(rng_x) = "Nothing" then Set rng_x = Range("L3:T11")

This may not be very efficient for a click handler. I can't find the code
where I used Worksheet_Activate, but I think it fires every time you switch
to the sheet, which may not provide the desired results. If it does fire in
that manner, you might combine the "lazy" method with the event handler.

(Excel 2003)

"Joe" wrote:

Hello guys,

My basics of VBA are poor..

I would like to know How I can Initialise certain things.. One time..

What I do now is..

' ***********
Public rng_source, rng_x As Range

Private Sub CommandButton1_Click()
n_Mat = 9

Set rng_source = Range("B3:J11")
Set rng_x = Range("L3:T11")

.....
end sub
' ************

1. I want to decalre it outside the function, may be when the sheet is
loaded.. Pls guide me..
2. If I declare that way, will it be visible in the Module Functions

Thanks all,

Joe