+ Reply to Thread
Results 1 to 4 of 4

VBA macro to put Formula in cell - too long?

Hybrid View

  1. #1
    Registered User
    Join Date
    08-16-2010
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2003
    Posts
    5

    VBA macro to put Formula in cell - too long?

    Hi,

    When I try to run the below code (it should copy the formula into the cell) I get the error message "Run-time error '1004': Application-defined or object-defined error".

    Is this because it is too long? If so, how could I shorten it?

    Thank you in advance for your help!

    Range("A4").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(ISERROR(IF(OR((LEFT(VALUE(RC[1]),10))=""7901699797"",(LEFT(VALUE(RC[1]),10))=""7901551774"",(LEFT(VALUE(RC[1]),10))=""7990076047"",(LEFT(VALUE(RC[1]),10))=""7990113923"",(LEFT(VALUE(RC[2]),6))=""743203"",(LEFT(VALUE(RC[2]),3))=""625"",(LEFT(VALUE(RC[2]),3))=""626"",(LEFT(VALUE(RC[2]),3)=""627"",(LEFT(VALUE(RC[2]),6))=""473203"")),"""",""delete"")),"""",IF(OR((LEFT(VALUE(RC[1]),10))=""7901699797"",(LEFT(VALUE(RC[1]),10))=""7901551774"",(LEFT(VALUE(RC[1]),10))=""7990076047"",(LEFT(VALUE(RC[1]),10))=""7990113923"",(LEFT(VALUE(RC[2]),6)=""743203"",(LEFT(VALUE(RC[2]),3))=""625"",(LEFT(VALUE(RC[2]),3))=""626"",(LEFT(VALUE(RC[2]),3)=""627"",(LEFT(VALUE(RC[2]),6)=""473203"")),"""",""delete""))"
    Last edited by mac8528; 08-16-2010 at 09:30 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,008

    Re: VBA macro to put Formula in cell - too long?

    You have mismatched parentheses, I think. I also don't see the purpose of the VALUE function if you are checking against a string, so try:
        ActiveCell.FormulaR1C1 = _
            "=IF(ISERROR(IF(OR(LEFT(RC[1],10)=""7901699797"",LEFT(RC[1],10)=""7901551774"",LEFT(RC[1],10)=""7990076047"",LEFT(RC[1],10)=""7990113923"",LEFT(RC[2],6)=""743203"",LEFT(RC[2],3)=""625"",LEFT(RC[2],3)=""626"",LEFT(RC[2],3)=""627"",LEFT(RC[2],6)=""473203""),"""",""delete"")),"""",IF(OR(LEFT(RC[1],10)=""7901699797"",LEFT(RC[1],10)=""7901551774"",LEFT(RC[1],10)=""7990076047"",LEFT(RC[1],10)=""7990113923"",LEFT(RC[2],6)=""743203"",LEFT(RC[2],3)=""625"",LEFT(RC[2],3)=""626"",LEFT(RC[2],3)=""627"",LEFT(RC[2],6)=""473203""),"""",""delete""))"
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    08-16-2010
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: VBA macro to put Formula in cell - too long?

    Thanks a lot, it works perfectly!

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,008

    Re: VBA macro to put Formula in cell - too long?

    Please don't forget to mark the question 'Solved'.

+ 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