LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default passing a range from another worksheet

Mike,

rng is being set as a Range object, but only in the module it is defined in.
It will not pass to another routine.

Excel works best when all variables are properly defined.
Improves speed and functioning.

Option Explicit at the top of each module forces Excel to only
accept defined variables. This helps catch typos and other errors
in your code. (it also drives you to distraction when you are first
learning how to use VBE)

When you use "set" you are defining an object. Excel likes this...

But when you use variables between modules you run into minor issues.

When you use Dim variable in a module - it won't pass to another module
When you use Dim variable outside a macro - it should pass to other macros
in the same module.
To pass variables to all macros in all modules - use Public variable outside
any
macro. (I usually do this by creating a module called "MyVariables" and
just
fill it with Public variables and add notes as to what they are.

But be careful - if you create a Public variable, don't dim this variable
inside of
any module - it can cause Excel to crash.

keep on Exceling...

--
steveB

Remove "AYN" from email to respond
"Mike O" wrote in message
...
Thanks for that Steve, setting the ranges in range variables did the trick
nicely.

One question though - I know VBA doesn't require the declaration of
variables, in theory. That said, if I do a

set rng = Sheet1.Range("C4:G8")

and attempt to pass this across to a Subroutine which is expecting a
Range,
I get a type mismatch. What type is VBA assigning to rng in this case? As
you
pointed out, declaring rng as a Range before setting it clears up this
problem, but I'm curious to know what it's being created as, if not as a
Range.

Thanks for the help,
Mike
--
--






 
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
Passing a Range Jerry Excel Programming 4 February 14th 05 10:52 AM
Passing a range into a VBA function Floyd[_2_] Excel Programming 4 February 10th 05 01:29 AM
passing range to c# Jerry Excel Programming 0 January 29th 05 08:29 PM
Passing range as argument Jan Kronsell[_2_] Excel Programming 3 September 3rd 03 12:31 PM
Passing range to subprocedure - maybe? Mike Gerbracht Excel Programming 2 July 26th 03 02:44 AM


All times are GMT +1. The time now is 09:45 AM.

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

About Us

"It's about Microsoft Excel"