+ Reply to Thread
Results 1 to 2 of 2

Long formulas to breakdown R1C1 style formulas in vba

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-18-2012
    Location
    Kuching, SARAWAK
    MS-Off Ver
    Excel 2010
    Posts
    116

    Long formulas to breakdown R1C1 style formulas in vba

    Hi Experts,

    Been trying to figure out this for half a day already.

    FormulaPart1 = "=IF(RC19="""","""",IF(AND(RC[-9]=""Rerouted to Creator"",OR(""OSB_USR""=INDEX(R2C3:R39C3,MATCH(1,(RC2=R2C2:R39C2)*(MIN(RC8:R39C8)=R2C8:R39C8),0)),RC21=INDEX(R2C6:R39C6,MATCH(1,(RC2=R2C2:R39C2)*(MIN(RC8:R39C8)=R2C8:R39C8),0)))),XXXXX, YYYYY))"
    FormulaPart2 = "INDEX(R2C7:R39C7,MATCH(1,(RC2=R2C2:R39C2)*(MIN(RC8:R39C8)=R2C8:R39C8),0)),IF(ISNA(MATCH(RC[11],UserID,0)),IF(LEFT(RC21,2)=""SA"",""AEGIS"",IF(OR(LEFT(RC21,4)=""JCVC"""
    FormulaPart3 = "LEFT(RC21,2)=""VC""),""VADS"",IF(LEFT(RC21,1)=""C"",""BlueCube"",IF(LEFT(RC21,2)=""V0"",""Other V"",""Celcom"")))),""SA"")))"
    
    Application.ReferenceStyle = xlR1C1
      
    With ActiveSheet.Range("AF2")
    .FormulaArray = FormulaPart1
    .Replace "XXXXX", FormulaPart2, lookat:=xlPart
    .Replace "YYYYY))", FormulaPart3, lookat:=xlPart
    End With
    
    Application.ReferenceStyle = xlA1
    Why when I run the macro, the output came out like below?:-
    {=IF($S2="","",IF(AND(W2="Rerouted to Creator",OR("OSB_USR"=INDEX($C$2:$C$39,MATCH(1,($B2=$B$2:$B$39)*(MIN($H2:$H$39)=$H$2:$H$39),0)),$U2=INDEX($F$2:$F$39,MATCH(1,($B2=$B$2:$B$39)*(MIN($H2:$H$39)=$H$2:$H$39),0)))),XXXXX, YYYYY))}

    Seems like it doesn't recognize the XXXXX and the YYYYY as strings that needs to be replaced...
    I've done this several times for other long formulas and it works, although it could be such a painful thing to do... but I just don't get it why this one doesn't work?

    Really appreciate if anyone out there can correct my formulas..

    Thanks in advance.
    DZ

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

    Re: Long formulas to breakdown R1C1 style formulas in vba

    The formula in the cell must be valid after each step - so where you break the formula strings apart is critical. The replacement is not being done because your part2 ends at a bad place, formula wise, which then makes the part3 replace fail too. So make sure your formula works after the XXXXX and before the YYYYY replacement and you should be good.
    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. Convert R1C1 Style to A1 style
    By m1ngle in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-17-2016, 08:38 PM
  2. [SOLVED] help with VBA formulas R1C1
    By stephme55 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-30-2015, 10:13 AM
  3. Multiple Loops, R1C1 & Array Formulas with VBA
    By 5150 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-02-2014, 02:18 PM
  4. [SOLVED] =IF and =SUMIF formulas creating long long long data processing times.
    By comp in forum Excel Programming / VBA / Macros
    Replies: 32
    Last Post: 03-26-2014, 02:59 PM
  5. Updating formulas using R1C1 syntax
    By lfeder in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-11-2013, 04:06 PM
  6. Evaluate function with R1C1 formulas
    By eiem in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-16-2010, 05:45 AM
  7. R1C1 Formulas
    By thundermocos in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-17-2007, 03:21 PM

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