+ Reply to Thread
Results 1 to 7 of 7

Break formula entry onto two lines in VBA.

  1. #1
    Registered User
    Join Date
    08-03-2015
    Location
    Southampton, England
    MS-Off Ver
    MS 2007
    Posts
    6

    Break formula entry onto two lines in VBA.

    Hi ExcelForum,

    I have a macro that uses the loop below, but the formula highlighted in red is too long to be incorporated within such a code (Exceeds character limit). I was hoping someone on here could show me how to break the formula down to allow it to be applied to the cells selected by the loop?

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Thanks,

    Fraser.

  2. #2
    Registered User
    Join Date
    08-13-2015
    Location
    Brussels
    MS-Off Ver
    2010
    Posts
    7

    Re: Break formula entry onto two lines in VBA.

    Hey Fraser

    Try something like this :

    form1 = "=MATCH(1,INDEX((R2C1:R30000C1=RC[-24])*(R2C4:R30000C4=RC[-21])*(R2C7:R30000C7=RC[-18])*(R2C9:R30000C9=RC[-16]),0,1),0)"
    form2 = "=IF(RC[-2]="""",INDEX(R2C6:R30000C6,MATCH(MIN(IF((ABS((((R2C25:R30000C25)=(RC[-1]))*(ABS(R2C23:R30000C23-RC[-15])))))<>0,ABS(((R2C25:R30000C25)=(RC[-1]))*(ABS(R2C23:R30000C23-RC[-15]))))),((R2C25:R30000C25)=(RC[-1]))*(ABS(R2C23:R30000C23-RC[-15])),0)),""-"")"

    For Row = 2 To 10000

    If Cells(Row, 22).Value = Sheets("Control").Cells(3, 2).Value Then

    Cells(Row, 25).Select

    Selection.FormulaArray = form1

    Cells(Row, 26).Select 'provides formula only to cells that need it.

    Selection.FormulaArray = form2

    Else: Cells(Row, 26).Value = "No Calc Required"

    End If

    Next Row

    Regards

    Geert

  3. #3
    Registered User
    Join Date
    08-03-2015
    Location
    Southampton, England
    MS-Off Ver
    MS 2007
    Posts
    6

    Re: Break formula entry onto two lines in VBA.

    Hi Geert,

    This doesn't seem to solve the issue of having a formula on multiple lines, rather it moves the problem to a different line? The error message 'Compile error: expected end of statement' now pops up. Any suggestions?

    Thanks,

    Fraser.
    Last edited by FraserMBrowning; 08-13-2015 at 07:41 AM.

  4. #4
    Registered User
    Join Date
    08-13-2015
    Location
    Brussels
    MS-Off Ver
    2010
    Posts
    7

    Re: Break formula entry onto two lines in VBA.

    Fraser

    The multiple lines were created by copying my code in the webinterface

    To combine two lines you have to use & _ e.g.

    form2 = "=IF(RC[-2]="""",INDEX(R2C6:R30000C6,MATCH(MIN(IF((ABS((((R2C25:R30000C25)=(RC[-1]))*(ABS(R2C23:R30000C23-RC[-15])))))<>0," & _ "ABS(((R2C25:R30000C25)=(RC[-1]))*(ABS(R2C23:R30000C23-RC[-15]))))),((R2C25:R30000C25)=(RC[-1]))*(ABS(R2C23:R30000C23-RC[-15])),0)),""-"")"

    Regards

    Geert

  5. #5
    Registered User
    Join Date
    08-03-2015
    Location
    Southampton, England
    MS-Off Ver
    MS 2007
    Posts
    6

    Re: Break formula entry onto two lines in VBA.

    Geert,

    My apologies, I had left off the '&' and simply used _. My mistake! Thanks for your help.

    Fraser.

  6. #6
    Registered User
    Join Date
    08-03-2015
    Location
    Southampton, England
    MS-Off Ver
    MS 2007
    Posts
    6

    Re: Break formula entry onto two lines in VBA.

    Hi Again,

    This still does not solve the problem, VBA is still telling me that the characters are too long, even if i define the formula as you suggested? Am I still doing/no doing something silly?

    Thanks again,

    Fraser.

  7. #7
    Registered User
    Join Date
    08-13-2015
    Location
    Brussels
    MS-Off Ver
    2010
    Posts
    7

    Re: Break formula entry onto two lines in VBA.

    Fraser

    I have tested it in excel 2010 and it works but excel 2007 allows less nested functions so that can be the problem.
    Maybe splitting the formula and putting the first result in an hidden column could do the trick

    Geert

+ 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. Statement break into two lines
    By kop1ko in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-03-2015, 04:01 PM
  2. help me break this formula into multiple lines on VBA
    By redplatinum2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2015, 07:35 PM
  3. Replies: 5
    Last Post: 06-30-2014, 08:30 PM
  4. Break down into multiple lines
    By jscalem in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-19-2014, 06:13 PM
  5. How do I break VBA code into two or more lines?
    By Kasama in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-31-2012, 09:27 PM
  6. [SOLVED] Break cell into multiple lines by line break
    By Chia in forum Excel General
    Replies: 1
    Last Post: 08-20-2006, 01:40 AM
  7. [SOLVED] Page Break lines
    By Steve DB in forum Excel General
    Replies: 3
    Last Post: 11-18-2005, 01:50 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