+ Reply to Thread
Results 1 to 8 of 8

Run-time error '1004'. Method 'Range' of object '_Global' failed

  1. #1
    Registered User
    Join Date
    02-08-2012
    Location
    Utah
    MS-Off Ver
    Excel 2007
    Posts
    15

    Run-time error '1004'. Method 'Range' of object '_Global' failed

    Hey everyone,
    I seem to be having an error with how I am assigning variables and after reading through articles on the Range object I have not figured out where I went wrong. The error highlights 'Set rngName = Range(nextrow, "A")'

    Here is my code:

    Please Login or Register  to view this content.
    The macro is designed to export values from a form into a reporting workbook, and then copy the entire original form into an employee file.
    Thanks, I really appreciate the help as always.
    Last edited by mjj347; 02-23-2012 at 02:06 PM.

  2. #2
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Run-time error '1004'. Method 'Range' of object '_Global' failed

    try


    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-08-2012
    Location
    Utah
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Run-time error '1004'. Method 'Range' of object '_Global' failed

    Thank you very much, I made that change but the error has changed to 'Application-defined or object-define error' 9 lines later with:
    Please Login or Register  to view this content.
    Last edited by mjj347; 02-23-2012 at 02:56 PM.

  4. #4
    Registered User
    Join Date
    02-08-2012
    Location
    Utah
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Run-time error '1004'. Method 'Range' of object '_Global' failed

    I also tried to add a temp variable to hold the cell address. While debugging I verified that temp = "A8" so rngName should be assigned that value. But the error I mentioned in the post above persists. Here is what I tried (the line highlighted by the error is bolded and underlined:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Run-time error '1004'. Method 'Range' of object '_Global' failed

    ok, your problem here seems to be trying to interchange the cells method of address and the range method of address. They are not interchangable. ie, if you address a cell thusly:

    Please Login or Register  to view this content.
    then to address the same cell using the cells method you would use:

    Please Login or Register  to view this content.

    One uses the Excel column and row (letter and number) and the other uses numerical values with the row addressed first. So.....if you have a variable set to cell "a10" then using that variable in a cells command results in you trying to input something like:

    Please Login or Register  to view this content.
    which is a syntax error.


    Geddit?
    Last edited by swoop99; 02-23-2012 at 05:37 PM.

  6. #6
    Registered User
    Join Date
    02-08-2012
    Location
    Utah
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Run-time error '1004'. Method 'Range' of object '_Global' failed

    That makes sense, thank you. And yes, I have no idea about VBA syntax. I have just been trying to find code that is close and adapt it, which leaves me in trouble at times. I have only been working with it for a week now :/.
    So would 'pastespecial' work the same way with the range object?
    The reason I am trying to do this is I started with code like this:
    Please Login or Register  to view this content.
    And so on for about 100 iterations. The problem is if I need to insert a new segment then I have to manually increment every column reference after it.
    So I wanted to use an offset function to that I can just pop a new segment in without messing the reporting sheet up.
    I just plugged this in but its generating the same error as the title of this thread, and before I spend a ton of time debugging it I would like to know what I am trying to do is possible:

    Please Login or Register  to view this content.
    If these blocks are syntactically correct then I can focus on checking my variables or something else. If there is an easier way to do this, using the nextrow variable then that would be great. Thank you again for your help.

  7. #7
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Run-time error '1004'. Method 'Range' of object '_Global' failed

    Close.

    You don't need the leading . on the range copy command or the leading ws. on the pastespecial command.

    You also need to set the rngname variable to the address property of the cell rather than just add the offset to it. Like this:

    Please Login or Register  to view this content.
    And really, don't worry one little bit about asking any questions you need an answer to. This is exactly what this forum is for, to aid learners in....well, learning. I started exactly the same way as you, not that long ago. Give it a few months and you'll be answering questions like this for people too.
    Last edited by swoop99; 02-23-2012 at 06:58 PM.

  8. #8
    Registered User
    Join Date
    02-08-2012
    Location
    Utah
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Run-time error '1004'. Method 'Range' of object '_Global' failed

    Ok great, thank you very much I will start with that and see if I can find what is going wrong.

+ 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