+ Reply to Thread
Results 1 to 2 of 2

Run time error 1004: Application-defined or object-defined error in long IF VBA formula

  1. #1
    Registered User
    Join Date
    01-28-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    4

    Run time error 1004: Application-defined or object-defined error in long IF VBA formula

    Hi I am new to Excel VBA (2010).

    Why am I getting this error on this part of my Sub?

    ActiveCell.FormulaR1C1 = _
    "=IF(AND(RC[-1]=""Heavy Oil"",RC[-20]=""HZ""),""Heavy Oil Hz"",IF(AND(RC[-1]=""Heavy Oil"",OR(RC[-20]=""VERT"",RC[-20]=""DIRE"",RC[-20]=""VERT"",RC[-20]=""SL"")),""Heavy Oil Slant + Vert"",IF(AND(RC[-1]=""SE SK"",RC[-20]=""HZ""),""SE SK Hz"",IF(AND(RC[-1]=""SE SK"",OR(RC[-20]=""Hz"",RC[-20]=""SL"",RC[-20]=""Vert"",RC[-20]=""Dire"")),""SE SK Slant, Vert, Dire"",IF(AND (RC[-1]=""NCAB"",RC[-20]=""HZ""),""NCAB Hz"",IF(AND(RC[-1]=""NCAB"",OR(RC[-20]=""SL"",RC[-20]=""Vert"",RC[-20]=""Dire"")),""NCAB Slant, Vert, Dire"",IF(AND(RC[-1]=""SCAB"",RC[-20]=""Hz""),""SCAB Hz"",IF(AND(RC[-1]=""SCAB"",OR(RC[-20]=""SL"",RC[-20]=""Vert"",RC[-20]=""Dire"")),""SCAB Slant, Vert, Dire"",IF(AND(RC[-1]=""GP"",RC[-20]=""Hz""),""GP Hz"",IF(AND(RC[-1]=""GP""," & _
    "OR(RC[-20]=""SL"",RC[-20]=""Vert"",RC[-20]=""Dire"")),""GP Slant, Vert, Dire"",IF(OR(RC[-1]=""Thermal"",RC[-20]=""Brintnell"",RC[-1]=""Wabiskaw Slant / Vertical"",RC[-1]=""Edson Deep Basin North"",RC[-1]=""Edson Deep Basin South""),RC[-1],IF(AND(RC[-1]=""BC"",RC[-20]=""Hz"",OR(RC[-2]=""Septimus"",RC[-2]=""Birch"")),""BC Conv Gas: Septimus, Birch Hz"",IF(RC[-1]=""BC"",""BC Conv Gas & Oil"","""")))))))))))))"

    I am adehering to the rules of:
    ..." & _
    "..........
    as well as the ""double quotation""

    Thanks for your help!

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,112

    Re: Run time error 1004: Application-defined or object-defined error in long IF VBA formul

    Try splitting your formulas into non-nested IF functions, getting each to work in a cell, along the lines of

    ActiveCell.Offset(0,1).FormulaR1C1 = _
    "=IF(AND(RC[-2]=""Heavy Oil"",OR(RC[-21]=""VERT""," & _
    "RC[-21]=""DIRE"",RC[-21]=""VERT"",RC[-21]=""SL"")),""Heavy Oil Slant + Vert"","""")"

    And then grab the correct value from all those formulas (based on it not being "") using a single formula.
    Bernie Deitrick
    Excel MVP 2000-2010

+ 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. [SOLVED] Run time error 1004 Application-Defined or Object-Defined Error - Placing data into next e
    By michelle 1 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-27-2014, 12:57 PM
  2. [SOLVED] Error " Run-time error '1004': application defined or object defined error
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2013, 07:26 AM
  3. [SOLVED] Macro causes Run time error 1004 Application defined or object-defined error
    By Firefighter in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-12-2012, 04:09 AM
  4. [SOLVED] run-time error '1004' application-defined or object-defined error - Excel 2007
    By kaurka in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2012, 02:46 AM
  5. Macro - Run-time Error '1004': Application defined or object defined error
    By robby10 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-14-2010, 07:55 AM

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