Results 1 to 7 of 7

Long array formula into VBA

Threaded View

  1. #1
    Registered User
    Join Date
    10-21-2014
    Location
    Macedonia
    MS-Off Ver
    2010
    Posts
    69

    Long array formula into VBA

    Thanks to @TMS and his extensive knowledge the following formula was offered to me as a wonderful solution:

    Formula: copy to clipboard
    =IF($A2="","",IF(MAX(ISNUMBER(MID($A2,ROW($A$1:INDEX($A:$A,LEN($A2))),1)+0)*ROW($A$1:INDEX($A:$A,LEN($A2))))=0,A2,   IFERROR(REPLACE($A2,  MAX(ISNUMBER(MID($A2,ROW($A$1:INDEX($A:$A,LEN($A2))),1)+0)*ROW($A$1:INDEX($A:$A,LEN($A2))))+1,  1,  " " & CHAR(149) & " "),$A2)&""))


    But because I need a dynamic header in the resulting spreadsheet I must use VBA.

    Since it has to be an array, there is a limit of 255 characters. But because of my lack of knowledge with any of this I am unable to divide correctly:

    Selection.FormulaArray = _
            "=IF(RC1="""","""",IF(MAX(ISNUMBER(MID(RC1,ROW(R1C1:INDEX(C1,LEN(RC1))),1)+0)*ROW(R1C1:INDEX(C1,LEN(RC1))))=0,RC[-1],   IFERROR(REPLACE(RC1,  MAX(ISNUMBER(MID(RC1,ROW(R1C1:INDEX(C1,LEN(RC1))),1)+0)*ROW(R1C1:INDEX(C1,LEN(RC1))))+1,  1,  "" "" & CHAR(149) & "" ""),RC1)&""""))"
    I would like to apply the following workaround but do not know where the mistake is:

    Sub LongArrayFormula()
         Dim theFormulaPart1 As String
         Dim theFormulaPart2 As String
         theFormulaPart1 = "=IF(RC1="""","""",IF(MAX(ISNUMBER(MID(RC1,ROW(R1C1:INDEX(C1,LEN(RC1))),1)+0)*ROW(R1C1:INDEX(C1,LEN(RC1))))=0,RC[-1],""X_X_X)"")"
                              
         theFormulaPart2 = "IFERROR(REPLACE(RC1,  MAX(ISNUMBER(MID(RC1,ROW(R1C1:INDEX(C1,LEN(RC1))),1)+0)*ROW(R1C1:INDEX(C1,LEN(RC1))))+1,  1,  "" "" & CHAR(149) & "" ""),RC1)&""""))"
         With ActiveSheet.Range("B2")
             .FormulaArray = theFormulaPart1
            .Replace """X_X_X)"")", theFormulaPart2
     
        End With
         
    End Sub
    Maybe the code does not work with RC1 formula. I do not know. I am using Excel 2010.

    In the end I would like to apply this formula to column B as long as there is content in Column A.

    Thank you so much for your help.
    Last edited by gokica; 03-27-2023 at 03:07 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Too long array formula to insert with VBA
    By KSimonsen87 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-24-2018, 03:11 PM
  2. [SOLVED] VBA for Long Array Formula
    By Dahlia in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-07-2018, 07:44 AM
  3. Long Array Formula in VBA (Help)
    By Hozcat in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2017, 10:43 AM
  4. Writing long array formula in VBA?
    By maym in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-28-2017, 02:44 AM
  5. [SOLVED] Long Formula Array
    By henxan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-04-2014, 09:03 AM
  6. Long Array Formula VBA
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-27-2011, 08:57 AM
  7. Long Array Formula Problem
    By tnederlof in forum Excel General
    Replies: 12
    Last Post: 08-20-2009, 02:55 PM

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