+ Reply to Thread
Results 1 to 6 of 6

Replace array formula in the code

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,149

    Replace array formula in the code

    Namaskar Experts
    This code was running fine till I had to replace one of the array formulas. I have run into an error. I need your expertise to replace the array formula for column H and get the correct result as shown in the expected result sheet (Doc1). As earlier I was suggested to share the data with expected results I am sharing both. If any of the members find it difficult to understand or want to write the code from the start in their own style you are most welcome. I have written all the steps I have used to create this application.
    TYIA
    Sorry! I forgot to change the sheet name in the code. I need help to correct just this one line of code which pastes data in column H. I am getting an error 1004.
    'Replace below with =SUM(--(FREQUENCY(MATCH(IF('EditB2B Expected'!B$2:B$100=B2,'EditB2B Expected'!D$2:D$100),IF('EditB2B Expected'!B$2:B$100=B2,'EditB2B Expected'!D$2:D$100),),MATCH(IF('EditB2B Expected'!B$2:B$100=B2,'EditB2B Expected'!D$2:D$100),IF('EditB2B Expected'!B$2:B$100=B2,'EditB2B Expected'!D$2:D$100),))>0))-1
           If lr = 2 Then
                .Range("H2").FormulaArray = "=SUM(--(FREQUENCY(--(IF('EditB2B'!B$2:B$" & _
                        Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & "=B2,'EditB2B'!D$2:D$" & Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & _
                        ",),5),--(IF('EditB2B'!B$2:B$" & Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & _
                        "=B2,'EditB2B'!D$2:D$" & Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & ",),5))>0))"
            Else
                .Range("H2").FormulaArray = "=SUM(--(FREQUENCY(--(IF('EditB2B'!B$2:B$" & _
                        Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & "=B2,'EditB2B'!D$2:D$" & Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & _
                        ",),5),--(IF('EditB2B'!B$2:B$" & Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & _
                        "=B2,'EditB2B'!D$2:D$" & Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & ",),5))>0))-1"
    '
    'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    Attached Files Attached Files
    Last edited by RAJESH SHAH; 06-24-2023 at 03:01 PM. Reason: #Solved
    "Where there is a will there is a way".

  2. #2
    Valued Forum Contributor
    Join Date
    11-27-2011
    Location
    usa
    MS-Off Ver
    Excel 2007, Excel 365
    Posts
    495

    Re: Replace array formula in the code

    I see a few lines of code there, which 'one line of code' are you referring to?

  3. #3
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,149

    Re: Replace array formula in the code

    The code is showing an error at this line in the end of module 2. If you run the code, the code will run through module one to module 2 and then it stops at this line with an error 1004.
    'Replace below with =SUM(--(FREQUENCY(MATCH(IF('EditB2B Expected'!B$2:B$100=B2,'EditB2B Expected'!D$2:D$100),IF('EditB2B Expected'!B$2:B$100=B2,'EditB2B Expected'!D$2:D$100),),MATCH(IF('EditB2B Expected'!B$2:B$100=B2,'EditB2B Expected'!D$2:D$100),IF('EditB2B Expected'!B$2:B$100=B2,'EditB2B Expected'!D$2:D$100),))>0))-1
           If lr = 2 Then
                .Range("H2").FormulaArray = "=SUM(--(FREQUENCY(--(IF('EditB2B'!B$2:B$" & _
                        Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & "=B2,'EditB2B'!D$2:D$" & Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & _
                        ",),5),--(IF('EditB2B'!B$2:B$" & Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & _
                        "=B2,'EditB2B'!D$2:D$" & Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & ",),5))>0))"
            Else
                .Range("H2").FormulaArray = "=SUM(--(FREQUENCY(--(IF('EditB2B'!B$2:B$" & _
                        Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & "=B2,'EditB2B'!D$2:D$" & Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & _
                        ",),5),--(IF('EditB2B'!B$2:B$" & Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & _
                        "=B2,'EditB2B'!D$2:D$" & Sheets("EditB2B").Range("A" & Sheets("EditB2B").Rows.Count).End(xlUp).Row & ",),5))>0))-1"
    '
    'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

  4. #4
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,149

    Re: Replace array formula in the code

    I have created a total of total of 9 modules same as above with a change difference in the filter value and 2 formulas to get the values. All are working without error except the above one. The other 9 modules have the same formula in column H and and as only this module was giving the incorrect result. So I had to change the formula to get the correct result. If I enter the new formula manually in the sheet I get the correct result but when I tried to edit that part in the code, I am getting an error and unable to view the result. If this issue is corrected than this will solve the problem.

  5. #5
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,149

    Re: Replace array formula in the code

    I may have figured out the actual problem in the code would be. There are a lot of calculations to be done in the code and I have added these lines to replace the formulas with values. By the time the code has completed the calculations the formulas are replaced with values with this code. Is it possible to insert a few lines for the code to finish the calculations and then run the last lines. After I commented these lines and ran the code I got the expected result. The last lines are
            'With .Range("A2", Sheets("DocSales").Range("A2").SpecialCells(xlLastCell))
            '    .Value = .Value
            'End With

  6. #6
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,149

    Re: Replace array formula in the code

    I have heard about Application manual / Application Automatic but I am unaware how and where to use it.
    Got it now. Placed this in the beginning of the code and it worked.
     Application.Calculation = xlCalculationAutomatic
    Last edited by RAJESH SHAH; 06-24-2023 at 03:00 PM.

+ 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] Need VBA Code to replace oldtext to new from looktable array
    By johnmacpro in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-04-2023, 09:01 AM
  2. VBA code replace few array and if formulas in workbook
    By ALEZI in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-17-2021, 08:01 AM
  3. Replace 0-Jan-00 in array formula
    By Motox in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-20-2019, 04:44 AM
  4. [SOLVED] Looking for possible code to replace large array function
    By Nitro2481 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2019, 01:23 PM
  5. [SOLVED] Replace ARRAY formula with VBA code
    By MariaPap in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-02-2014, 08:29 AM
  6. [SOLVED] Formula to replace this array
    By cboys00 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-06-2012, 08:47 PM
  7. Replace hard coded array in formula with link to input array
    By David Brown in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-08-2011, 07:45 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