+ Reply to Thread
Results 1 to 12 of 12

Run time error 1004 - Method 'Range' of 'Object'_Global' failed

  1. #1
    Registered User
    Join Date
    01-23-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    58

    Run time error 1004 - Method 'Range' of 'Object'_Global' failed

    Hi I am trying to build a macro which will format the columns of a spreadsheet - basically it inserts some columns, writes formulas and highlights them. Here is a code I have got so far...

    When I try to run this I get a run time error 1004 - Method 'Range' of 'Object'_Global' failed. The part of the code
    Range("N2:N").FormulaR1C1 = "=(RC[-7]/RC[-2])"

    is highlighted in the debugger.

    Can anyone tell me why this is happening, also it would be great if you could suggest better ways of writing this code - as I am new to vba programming and most of my macros are built using the recorder and then 'working' on them.

    Thanks.


    Please Login or Register  to view this content.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

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

    Range("N2:N") doesn't describe a range; it needs a row number for the second N.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    01-23-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    58

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

    Ok, I will need it to do it for variable number of rows since the number of rows will difffer with the data - do I need to define a lastrow variable? if so, how can I do that?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

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

    Perhaps
    Please Login or Register  to view this content.
    ... however you calculate nRows

  5. #5
    Registered User
    Join Date
    01-23-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    58

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

    I did this...

    Please Login or Register  to view this content.
    ....it gives me the same error again...

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

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

    How did you calculate nRows?

  7. #7
    Registered User
    Join Date
    01-23-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    58

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

    I did not and I do not know how to...

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

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

    Me either -- I don't know what you're doing.

  9. #9
    Registered User
    Join Date
    01-23-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    58

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

    I am trying to get it to write that formula in all cells from N2 to the last row of the data.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

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

    Try
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    01-23-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    58

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

    It worked. Thanks - Is there anything else you would suggest to clean up the code?

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

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

    It's hard to tell by looking at the code.

+ 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