+ Reply to Thread
Results 1 to 10 of 10

Error 1004 when pasting a long formula in Macro

  1. #1
    Registered User
    Join Date
    03-14-2017
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    5

    Error 1004 when pasting a long formula in Macro

    I need to use a macro for a long formula but I keep getting a 1004 error when i try to use the Macro. The formula works fine when i enter it into a cell manually. When i click debug everything from "Selection.FormulaR1C1" to the end of the formula gets highlighted yellow.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Error 1004 when pasting a long formula in Macro

    I can't enter that formula by hand.
    There seems to be something missing in your first line break
    The first line ends with
    R2C[
    But the next line begins with
    ))*

    So that would become R2C[))
    Something is missing between [ and )

  3. #3
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Error 1004 when pasting a long formula in Macro

    Can you post the actual formula you put in the cell by hand while you were recording the macro ?

  4. #4
    Registered User
    Join Date
    03-14-2017
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    5

    Re: Error 1004 when pasting a long formula in Macro

    =sqrt((((sqrt((j$2-j$3)^2+(l$2-l$3)^2))+(sqrt((j$2-a2)^2+(l$2-c2)^2))+(sqrt((j$3-a2)^2+(l$3-c2)^2)))/2)*((((sqrt((j$2-j$3)^2+(l$2-l$3)^2))+ (sqrt((j$2-a2)^2+(l$2-c2)^2)) +(sqrt((j$3-a2)^2+(l$3-c2)^2)))/2) -(sqrt((j$2-j$3)^2+(l$2-l$3)^2)))*((((sqrt((j$2-j$3)^2+(l$2-l$3)^2)) +(sqrt((j$2-a2)^2+(l$2-c2)^2)) +(sqrt((j$3-a2)^2+(l$3-c2)^2)))/2) -(sqrt((j$2-a2)^2+(l$2-c2)^2)))*((( (sqrt((j$2-j$3)^2+(l$2-l$3)^2))+(sqrt((j$2-a2)^2+(l$2-c2)^2))+(sqrt((j$3-a2)^2+(l$3-c2)^2)))/2)-(sqrt((j$3-a2)^2+(l$3-c2)^2))))

  5. #5
    Registered User
    Join Date
    03-14-2017
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    5

    Re: Error 1004 when pasting a long formula in Macro

    Please Login or Register  to view this content.

  6. #6
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Error 1004 when pasting a long formula in Macro

    Here's the working code resulting from the Macro Recorder when I enter that formula by hand.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-14-2017
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    5

    Re: Error 1004 when pasting a long formula in Macro

    When i replace my formula with that I just get 0s. I think im just putting it in the wrong cell because of the difference in RC. But if it owrk by hand is the problem the copy and pasting?

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Error 1004 when pasting a long formula in Macro

    It's going to depend on where you put the formula (i.e. what is ActiveCell or Selection)

    The range references are all written with mixture of absolute and relative styles.
    So it will end up different in J10 than it did in say G2.

    So when you're using the macro recorder, make not of which cell you actually have active when you manually type the formula.
    Then when you run the resulting macro, it has to put the formula into the same cell.

  9. #9
    Registered User
    Join Date
    03-14-2017
    Location
    Toronto
    MS-Off Ver
    2010
    Posts
    5

    Re: Error 1004 when pasting a long formula in Macro

    Is there a way I can paste the formula without having it cut off like shown in my first post so i dont have to do it by hand?

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

    Re: Error 1004 when pasting a long formula in Macro

    Just for future reference.

    If you have a working formula in a cell and you want it in code, do as follows:

    Select the cell with the working formula.
    Developer, Record Macro, yes to the suggested macro name
    F2
    Enter
    Developer, Stop recording.

    Go to your macro that you just recorded and you'll see the formula in code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Long Formula Getting 1004 error when running VBA
    By johnmahon12 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-25-2016, 08:08 AM
  2. Replies: 1
    Last Post: 03-12-2014, 12:42 PM
  3. long formula to vba macro - error 1004 unable to set formulaarray property
    By desibabuji in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-08-2013, 06:18 AM
  4. Replies: 1
    Last Post: 05-06-2013, 06:07 AM
  5. Run Time Error 1004 pasting formula into worksheet using VBA.
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2012, 09:42 PM
  6. Macro fails at pasting (Run-time error '1004' Paste method fail)
    By SergioS in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-09-2010, 02:17 PM
  7. Excel 1004 Error When Pasting Special W/ Macro
    By setoFairfax in forum Excel General
    Replies: 2
    Last Post: 04-27-2005, 10:06 AM

Tags for this Thread

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