+ Reply to Thread
Results 1 to 6 of 6

Name a dynamic range - Run-time error 1004 Method 'Range' of object'_Worksheet' failed

  1. #1
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Name a dynamic range - Run-time error 1004 Method 'Range' of object'_Worksheet' failed

    Hello

    Just written a simple (or so I thought!) macro to give a name to dynamic range but get the runtime error 1004 message in the thread title.

    Code is as follows:

    PHP Code: 
    Sub RangeNameUpdate()
    '
    RangeNameUpdate Macro
    ' Macro recorded 03/05/2012
    '
    Dim ws As Worksheet
    Dim MyRange 
    As Range

    Set ws 
    Worksheets("LOOKUP")
        
        
    With Sheets("LOOKUP")
        
    Columns("A:A").Select
        Selection
    .Delete Shift:=xlToLeft
        Set MyRange 
    ws.Range("A3:A"ws.Range("A" ws.Rows.Count).End(xlUp).Row)
        
    End With
        ActiveWorkbook
    .Names("WORKSHEETS").Delete
        MyRange
    .Name "worksheets"
        
    End Sub 
    Error appears on line starting "Set MyRange = "

    Would be grateful for the fix!

    Thanks

  2. #2
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Name a dynamic range - Run-time error 1004 Method 'Range' of object'_Worksheet' failed

    Please Login or Register  to view this content.
    Should be:
    Please Login or Register  to view this content.
    Think of:

    Please Login or Register  to view this content.
    as a String, where you are adding a number to "A3:A"

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,368

    Re: Name a dynamic range - Run-time error 1004 Method 'Range' of object'_Worksheet' failed

    Try:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,368

    Re: Name a dynamic range - Run-time error 1004 Method 'Range' of object'_Worksheet' failed

    Note that there are other things wrong with your original code.

    Please Login or Register  to view this content.

    could be:

    Please Login or Register  to view this content.

    But then you need to "connect" the Columns property with a full stop/dot (.) And lose the references to "ws".

    You should also avoid selecting "something" and then taking action on the selection. Combine the two as in my example.

    Regards, TMS

  5. #5
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Name a dynamic range - Run-time error 1004 Method 'Range' of object'_Worksheet' failed

    Thank you both for the solutions and the tips

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,368

    Re: Name a dynamic range - Run-time error 1004 Method 'Range' of object'_Worksheet' failed

    You're welcome.

+ 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