Results 1 to 7 of 7

Translate array formula to VBA code

Threaded View

  1. #1
    Forum Contributor
    Join Date
    12-23-2013
    Location
    Hungary
    MS-Off Ver
    Excel 2013
    Posts
    331

    Translate array formula to VBA code

    Hello,

    I would like to translate the below mentioned array formula to VBA code but I can not set the FormulaArray property. The expected results are in the column R.

    The array formula:

    =IF(COUNTIFS(BOM!C:C,D9,BOM!N:N,"ACTIVE MELANGE")/SUM(IF(D9=BOM!C9:C11991,1/(COUNTIFS(BOM!C9:C11991,D9,BOM!I9:I11991,BOM!I9:I11991)),0))=1,"Mono material",IF(COUNTIFS(BOM!C:C,D9,BOM!N:N,"ACTIVE MELANGE")/SUM(IF(D9=BOM!C9:C11991,1/(COUNTIFS(BOM!C9:C11991,D9,BOM!I9:I11991,BOM!I9:I11991)),0))=2,"Bi material","Not assigned"))

    The code until now, but doesn't work:

    Option Explicit
    Sub GetData()
    Dim LastRow As Long
    Dim OutputSheet1 As Worksheet
    Dim OutputLastRow1 As Long
    Dim OutputSheet2 As Worksheet
    Dim OutputLastRow2 As Long
    Dim myFormula2 As String
    
        Set OutputSheet1 = Worksheets("BOM")
        Set OutputSheet2 = Worksheets("Evaluation")
         
        With OutputSheet2
            OutputLastRow2 = .Cells(.Rows.Count, "B").End(xlUp).Row
            myFormula2 = "=IF(COUNTIFS(BOM!R9C3:R" & OutputLastRow1 & "C3=RC[-4],D9,BOM!R9C19:R" & OutputLastRow1 & ",""ACTIVE MELANGE"")/SUM(IF(D9=BOM!R9C3:R" & OutputLastRow1 & ",1/(COUNTIFS(R9C3:R" & OutputLastRow1 & ",D9,BOM!R9C9:R" & OutputLastRow1 & ",BOM!R9C9:R" & OutputLastRow1 & ")),0))=1,""Mono material"",IF(COUNTIFS(BOM!R9C3:R" & OutputLastRow1 & "C3=RC[-4],D9,BOM!R9C19:R" & OutputLastRow1 & ",""ACTIVE MELANGE"")/SUM(IF(D9=BOM!R9C3:R" & OutputLastRow1 & ",1/(COUNTIFS(R9C3:R" & OutputLastRow1 & ",D9,BOM!R9C9:R" & OutputLastRow1 & ",BOM!R9C9:R" & OutputLastRow1 & ")),0))=2,""BI material"",""Not assigned""))"
            Range("Q9").FormulaArray = myFormula2
            Range("Q9").Copy Range("Q10:Q" & OutputLastRow2)
            Application.CutCopyMode = False
        End With
        
    End Sub
    The code is stop at this line:

    Range("Q9").FormulaArray = myFormula2
    Could somebody give me advice where I made mistake?

    The sample file has been attached to this thread!



    Thanks in advance the reply.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro: translate text from cell using google translate
    By Marc_excel_tips in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 01-05-2021, 06:18 AM
  2. Sample Translate English to Arabic Text Using MS Translate
    By pidyok in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2013, 08:18 AM
  3. Translate Formula to VBA Code
    By mkeys4 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2013, 12:44 PM
  4. [SOLVED] translate ws formula to vba code
    By L Scholes in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-16-2006, 10:40 PM
  5. Replies: 5
    Last Post: 04-04-2005, 05:06 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