+ Reply to Thread
Results 1 to 3 of 3

Different usage of range formats, conflict?

  1. #1
    Registered User
    Join Date
    08-13-2006
    Posts
    2

    Different usage of range formats, conflict?

    Hi all,
    I've got confused with many range formats. In Help site of MS Office 2003 told that these 2 types of range is the same:
    ex1: Range("A1:C20")
    ex2: Range(cells(1,1),cells(20,3))
    However I've found that they are different in using.
    ex1: sheets(1).Range("A1:C20").copy(sheets(2).range("A1")) --> It's working
    ex2: sheets(1).Range(cells(1,1),cells(20,3)).copy(sheets(2).range("A1")) --> fail
    Object-defined error????
    I really dont know what is the different thing here? The same case with others functions using with range?
    Anybody meet the same problem like me? plz give me some hints or show me the solving? thanks a lots!!!

  2. #2
    Peter T
    Guest

    Re: Different usage of range formats, conflict?

    Whenever Cells(1,1) is not prefixed with a dot it refers to a cell on the
    activesheet, unless the code is in a sheet module in which case it refers to
    that sheet (typically but not necessarily the active sheet).

    sheets(1).Range(cells(1,1),cells(20,3))

    will only work if Sheets(1) is the active worksheet

    Instead try

    Worksheets(1).Range(Worksheets(1).Cells(1,1), Worksheets(1)..Cells(20,3))

    or

    With Worksheets(1)
    .Range(.Cells(1,1), .Cells(20,3)) etc
    End With

    Note the dot prefix .Cells(

    Alternatively
    Worksheets(1).Range("A1:C" & 20)

    In passing note Sheets(1) in this context would fail if a chart sheet

    Regards,
    Peter T


    "azzura" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi all,
    > I've got confused with many range formats. In Help site of MS Office
    > 2003 told that these 2 types of range is the same:
    > ex1: Range("A1:C20")
    > ex2: Range(cells(1,1),cells(20,3))
    > However I've found that they are different in using.
    > ex1: sheets(1).Range("A1:C20").copy(sheets(2).range("A1")) --> It's
    > working
    > ex2:
    > sheets(1).Range(cells(1,1),cells(20,3)).copy(sheets(2).range("A1")) -->
    > fail
    > Object-defined error????
    > I really dont know what is the different thing here? The same case with
    > others functions using with range?
    > Anybody meet the same problem like me? plz give me some hints or show
    > me the solving? thanks a lots!!!
    >
    >
    > --
    > azzura
    > ------------------------------------------------------------------------
    > azzura's Profile:

    http://www.excelforum.com/member.php...o&userid=37450
    > View this thread: http://www.excelforum.com/showthread...hreadid=571156
    >




  3. #3
    Registered User
    Join Date
    08-13-2006
    Posts
    2

    RE: Different usage of range formats, conflict?

    Yeah, thanks Peter.
    It works well. It's just a little hint but help me

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1