LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #11   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default syntax question

Got it. I figured it might be a typo, but I wasn't sure if you had some
other points in mind.
--
Thanks for the feedback,
Jay

"Dave Peterson" wrote:

If you're writing about this line:

set i = ws.Range(ws3.Cells(2, x), ws3.Cells(lRow, x))
then you're right. But it was more of a typo (copy|paste) error than anything.

set i = ws.Range(ws.Cells(2, x), ws.Cells(lRow, x))

(I copied from a combination of previous posts and should have just typed the
line in the message.)

But I'll stand by the one I actually typed!

dim ws as worksheet
dim i as range
set ws = worksheets("someothersheet")
with ws
set i = .Range(.Cells(2, x), .Cells(lRow, x))
end with







Jay wrote:

Hi Dave - could you check your syntax ? I might be misunderstanding your
post, but both statements you posted produce an error (winXP/XL03) regardless
of the location (general module or worksheet module).

My thought is that this type of statement can never ask for the range object
from one worksheet based on the cells object from another; they're
incompatibility produces the error.

Let us know what you think...

--
Respectfully,
Jay

"Dave Peterson" wrote:

It also depends on where the code is.

An unqualified range (without the ws. stuff) in a general module, will refer to
the activesheet.

An unqualified range in a worksheet module will refer to the sheet that owns the
code.

dim i as range
set ws = worksheets("someothersheet")
'this will always work
set i = ws.Range(ws3.Cells(2, x), ws3.Cells(lRow, x))

'this will cause an error if you're in a worksheet module (not someothersheet,
though):
set i = ws.Range(Cells(2, x), Cells(lRow, x))


=====
To save typing (and easier to understand (for me at least)), I'd use:

dim ws as worksheet
dim i as range
set ws = worksheets("someothersheet")
with ws
set i = .Range(.Cells(2, x), .Cells(lRow, x))
end with

Note the dot's in front of .range and both .cells.






Gary Keramidas wrote:

just wondering if these are functionally the same:

i = Range(ws3.Cells(2, x), ws3.Cells(lRow, x))
i = ws3.Range(Cells(2, x), Cells(lRow, x))

--

Gary

--

Dave Peterson


--

Dave Peterson

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax question BigDave63 Excel Worksheet Functions 4 February 5th 09 06:50 PM
VBA syntax question Matt Excel Discussion (Misc queries) 2 December 5th 07 03:08 PM
syntax question Giselle Excel Worksheet Functions 4 January 29th 06 01:59 AM
Syntax question Stuart[_5_] Excel Programming 3 December 3rd 03 08:45 PM
VBA Syntax Question? Michael168[_54_] Excel Programming 0 November 5th 03 11:02 AM


All times are GMT +1. The time now is 05:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"