+ Reply to Thread
Results 1 to 4 of 4

Syntax of Range

Hybrid View

avveerkar Syntax of Range 03-20-2007, 08:04 AM
Simon Lloyd Hi, you cannot SELECT a range... 03-20-2007, 08:30 AM
avveerkar Thanks a lt Simon. That will... 03-20-2007, 08:34 AM
avveerkar I am on sheet1 and I run this... 03-20-2007, 01:46 PM
  1. #1
    Forum Contributor
    Join Date
    01-10-2006
    Location
    Ahmedabad, India
    MS-Off Ver
    Office 2000
    Posts
    346

    Syntax of Range

    My code is in standard module of a workbook. I want to select a range in say sheet3. If I use
    Worksheets("sheet3").Range(Cells(1,1), Cells(5,5)).Select
    it won'r work ( gives run time error ) unless sheet3 is activated before I execute this line of code.
    What is the syntax to use Range property on a sheet which has not been activated?

    A V Veerkar

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Hi, you cannot SELECT a range on a sheet that is neither visible or activated, to use select you would have to select the sheet, but you do not need to select things in order to manipulate them, take a look at this:

    Option Explicit
    
    Sub copypaste_without_selecting()
    Dim Rng As Range
    Set Rng = Sheets("Sheet3").Range("A1:E5") '''sets range without selecting
    Rng.Copy Destination:=Sheets("Sheet1").Range("A1") '''copies range without selecting
    End Sub                                       '''pastes to Sheet1 without selecting
    even if you were on sheet 2 and ran tis code it would perform the task!

    Regards,
    Simon

  3. #3
    Forum Contributor
    Join Date
    01-10-2006
    Location
    Ahmedabad, India
    MS-Off Ver
    Office 2000
    Posts
    346
    Thanks a lt Simon. That will help.
    A V Veerkar

  4. #4
    Forum Contributor
    Join Date
    01-10-2006
    Location
    Ahmedabad, India
    MS-Off Ver
    Office 2000
    Posts
    346
    Quote Originally Posted by Simon Lloyd
    Hi, you cannot SELECT a range on a sheet that is neither visible or activated, to use select you would have to select the sheet, but you do not need to select things in order to manipulate them, take a look at this:

    Option Explicit
    
    Sub copypaste_without_selecting()
    Dim Rng As Range
    Set Rng = Sheets("Sheet3").Range("A1:E5") '''sets range without selecting
    Rng.Copy Destination:=Sheets("Sheet1").Range("A1") '''copies range without selecting
    End Sub                                       '''pastes to Sheet1 without selecting
    even if you were on sheet 2 and ran tis code it would perform the task!

    Regards,
    Simon
    I am on sheet1 and I run this code
    set rng=sheets(2).Range("A1:E5")
    it works ok. But if I change to
    set rng=sheets(2).Range(cells(1,1),cells(5,5))
    it gives error. I want to use the second notation. Any idea how to use the second notation with Range property to return a range from other sheet?

    A V Veerkar

+ 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