View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default To Set or not to Set that is the question

I agree with what Jim wrote, but I would have used:
swk, not swb. It represents a worksheet, not a workbook <bg.

And what's even nicer if you declare your variables nicely:

Dim swk as worksheet
dim dwk as worksheet

You'll get the VBE's intellisense to pop up.

Type swk. (include the dot) and you'll see a list of all the properties/methods
that you can use.



Desert Piranha wrote:

Hi all,

Thx to some very nice and briliant folks here, i have a workbook that's
working great.
But in my quest to learn, i am courious about this.

I have several (6+) blocks of code like below. All of the source
workbook and worksheets references
are the same, and all of the destination workbook and worksheet
references are the same.
The ranges are the only difference.

'Copy site data
Workbooks("UCPSITE-06.xls").Sheets("UCP SITE -
Totals").Range("D227:BD303").Copy
'Paste site data
Workbooks("3140UCP2006WithShell.xls").Sheets("3140 UCP Totals
2006").Range("D3").PasteSpecial _
Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False,
Transpose:=False
'Clears Clipboard
Application.CutCopyMode = False

So if i set the WorkBook at the begining of the code, Something like
this:

'Source workbook
Set swb = Workbooks("UCPSITE-06.xls").Sheets("UCP SITE - Totals")
'Destination workbook
Set dwb = Workbooks("3140UCP2006WithShell.xls").Sheets("3140 UCP
Totals 2006")

then in my blocks of code use something like:

swb.Range("D227:BD303").Copy
dwb.Range("D3").PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
'Clears Clipboard
Application.CutCopyMode = False

Soo what are the pros and cons of something like this?

--
Desert Piranha

------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=572376


--

Dave Peterson