+ Reply to Thread
Results 1 to 4 of 4

Select Range Question

Hybrid View

  1. #1
    Registered User
    Join Date
    01-25-2013
    Location
    Wicita, Kansas
    MS-Off Ver
    Excel 2003
    Posts
    5

    Select Range Question

    I am sure I doing something simple to make this error out but I just can't see it. I followed examples but no joy? See the comment in the code for the question; thanks.


    Sub MySelection()
    Dim MyData As Range
    Set MyData = Range("A1:D5")
    
    ' Why does the next line error out "Run-Time error 1004
    '    (Method range of global object failed)
    
    Range("MyData").Select
    
    'While the next line's direct reference to the range does work?
    
    Range("A1:D5").Select
    End Sub
    Last edited by Leith Ross; 02-04-2013 at 07:57 PM. Reason: Added Code Tags

  2. #2
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Select Range Question

    Try this.

    Sub MySelection()
    Dim MyData As Range
    Set MyData = Range("A1:D5")
    MyData.Select
    End Sub
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  3. #3
    Registered User
    Join Date
    01-25-2013
    Location
    Wicita, Kansas
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Select Range Question

    Thank you so very much that did it and I understand what I did wrong now.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,722

    Re: Select Range Question

    Instead of

    Set MyData = Range("A1:D5")
    use

    Range("A1:D5").Name = "MyData"
    Too late I guess.
    From what I see is that one names a range and mine creates a named range.
    Last edited by jolivanes; 02-04-2013 at 07:17 PM.

+ 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