LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default first sip of working with range in vba excel

"bpascal123" wrote in message
...
Hi,

I replaced
wks2.Range(Cells(1, 1), Cells(10, 3)) = wks1.Range(Cells(1, 1),
Cells(10, 3)).value

with
wks2.Range(wks2.Cells(1, 1), wks2.Cells(10, 1)) =
wks1.Range(wks1.Cells(1, 1), wks1.Cells(10, 3)).Value

Honestly, i haven't been able to see i needed to link the cell
property in a range to a specific worksheet. Because to me, the range
object is already linked to a specific worksheet then the cells
property in the range object doesn't to be linked to a specific range
on a worksheet



Pascal, does the built-in help make sense to you? I found that it took
me quite a significant period of time before the object model and the
distinctions between objects, properties and methods began to actually
make sense to me. By "quite a significant period of time" memory tells
me that means some months, not days or even a few weeks.

From the VBE window enter [ range property ] in the help search box --
you should get a list of articles to choose from. Quoting from that help
text:

<qWhen used without an object qualifier, this property is a shortcut
for ActiveSheet.Range (it returns a range from the active sheet; if the
active sheet isn't a worksheet, the property fails).</q

In other words, when you use Range (or Cell) in code without a
qualifier, VBA uses the ActiveSheet object -- which may or may not be
what you expect it to be.

What you said above is an excellent illustration of why it is necessary
to develop an understanding of the rules that govern the compiler. In
this case, what seems to be "common sense" to you is in fact a violation
of the rules that the complier follows.

wks2.Range(Cells(1, 1), Cells(10, 3)) = wks1.Range(Cells(1, 1),
Cells(10, 3)).value


*cannot* work, because you are expecting the Cells property to return
cells from two different worksheets ... but there is only one
AcitveSheet (and it could easily be neither wks1 nor wks2!)

One of the things that was difficult for me to grasp is that there are
both Range properties and Range objects ... and they do entirely
different things. Let's see if I can summarize: The Cells property
returns a Range Object consisting of a single cell. The Range property
(many objects have a Range property- for instance: Excel Application
Window objects, Worksheet objects and Range objects to name three) also
returns a Range object - which may contain one or many cells, included
in one or many areas. VBA rules allow you to use Range and Cells with or
without object qualifiers - but if you do not qualify (disambiguate) the
default object is always the active sheet.

HTH!

--
Clif McIrvin


(clare reads his mail with moe, nomail feeds the bit bucket :-)


 
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
Working with Range Robin Clay[_4_] Excel Programming 3 November 7th 08 07:53 PM
Working with a range Dan Chupinsky Excel Discussion (Misc queries) 3 July 6th 05 06:39 AM
Working with range François Excel Programming 6 April 28th 05 01:37 PM
Macro working in Excel 2003; not working in Excel 2000 Leslie Barberie Excel Programming 5 May 20th 04 07:51 PM
Excel VBA-Error, range function not working?!?!? waveracerr[_15_] Excel Programming 2 February 13th 04 08:11 PM


All times are GMT +1. The time now is 06:19 PM.

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"