# Explaining soem code...

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

Hi,

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

Cheers

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
.range("A1")=25
.range("A1:Z100").interior.colorindex=2
.range("C2:AC200").formula="=A1+B2"
end with

Rather then
Worksheets("Totals").range("a1")=25
Worksheets("Totals").range("a1:z100").interiro.colorindex=2
etc.

LastRow as Long
iRow as long
iList as integer

These speak for themselves.......ie
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.

HTH

Ivan

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

Cheers

Thats a great help.