MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Explaining soem code...

Posted by M Walker on August 23, 2001 1:35 AM


Could anybopdy explain the following code;

Dim wsSI as worksheet
Set wsSI = Worksheets("Totals")

Dim LastRow As Long
Dim iRow As Long
Dim iList As Integer


Posted by Ivan F Moala on August 23, 2001 2:24 AM

The code looks like a setup to reference
a sheets rows and ranges therin.

The declarations;
Dim wsSI as worksheet
- Assigns variable wsSI as an object = Worksheet
Why do this ?
It is quicker and easier to reference this latter
in the code eg.

set wsSI = Worksheets("Totals")

With wsSI
end with

Rather then

LastRow as Long
iRow as long
iList as integer

These speak for
LastRow = LastRow and is dim as a long as we
have 65536 possible rows so it cannot be dim as
an Integer. Longs are stored as signed 32-bit (4-byte) numbers ranging in value from -2,147,483,648 to 2,147,483,647.

iRow I'm guessing is an IndexRow variable that
will reference a counter or possition.
iList I'm guessing is an Index to a list range
or list of some sort.....BUT is limited to only
32768 = Integer. Integers are stored as 16-bit (2-byte) numbers ranging in value from -32,768 to 32,767.

Always Declare your variabls, otherwise they will default to Variants which are powerful but slow.
Use them only when you have to or when it doesn't matter. Ideally, use integers or booleans wherever possible, followed by long, single and double.

Have a look @ online help for these.



Posted by Matt Walker on August 23, 2001 2:33 AM


Thats a great help.