Both Activesheet.Name and Selection.Address (assuming a cell/range is
selected, not, say, a button) are strings.
But re "Used to reference a worksheet at a later time" it is simpler to do
this:
Dim WS as Worksheet
Set WS = ActiveSheet
.....and later:
WS.Activate
than to do what you're thinking of:
Dim WSName as String
WSName = ActiveSheet.Name
...and later:
Worksheets(WSName).Activate
--
Jim
| Ok, now that I realize that I should be declaring all variables.
|
| Is there an easy way to determine what type of variable to assign. For
| instance, I am trying to declare a variable for a SheetName such as:
|
| ShNM = Activesheet.Name
|
| --Used to reference a worksheet at a later time -- What type should I use
| here?
|
| Also,
|
| SelAd = Selection.Address
|
| --Used to reference a cell at a later time --What type should I use here?
I
| have tried several and Variant is the only one that works. Is this really
the
| best?
|
|
|
|
| "Ron Rosenfeld" wrote:
|
| > On Mon, 10 Oct 2005 12:15:02 -0700, tjh <
[email protected]>
wrote:
| >
| > >What is the primary benfit of a Dim statement -- if the variable does
not
| > >cause any name or data type confusion.
| > >
| > >I understand that it is to declare a variable. However, I seem to be
able to
| > >run macros without any problem no matter if I declare the varaiable or
do not.
| > >
| > >For instance, I use For Next loops similar to:
| > >
| > >Dim intI as integer
| > >For intI = 1 to 25
| > > ................
| > > ................
| > >Next intI
| > >
| > >but these loops work the same weither I declare the variable or not.
| > >
| > >Any thoughts?
| > >
| > >Thank You,
| > >
| > >
| > >
| >
| > The reason *you* can use it either way, in your code, is because you do
not
| > have the Option Explicit statement at the beginning.
| >
| > See
http://www.cpearson.com/excel/DeclaringVariables.htm for a
discussion as to
| > the benefits of using the Option Explicit statement (and declaring
variables).
| >
| >
| > --ron
| >