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
--
--
|