FormulaArray in Excel Macro

goliathh

New Member
Joined
Oct 23, 2016
Messages
3
Hi all,

I have been referring to this forum quite a fair bit recently to learn about Excel Macro from fellow experts in here. And for that, I want to thank you all first.

I have also referred some threads related FormulaArray too... which comes to the main reason of this thread.

I know that FormulaArray has its characters limitation and hence, I have tried playing around with Replace function to make my formula 'appear' shorter.

I have tried both options (1 & 2) below but somehow, they do not work for some reason.

And hence... the emerge of this thread asking for fellow experts in here to help me verify / troubleshoot my (messy) codes.

Below are the codes for...

Option 1
Code:
[FONT=Helvetica Neue][FONT=Courier New][SIZE=2]Sub CompleteHCData()

Dim LastRow4 As Long
Dim x As Long
Dim VAPP As Worksheet

    Sheets("Summary").Activate
    
    Set VAPP = ActiveWorkbook.Sheets("Plan Output")
    LastRow4 = VAPP.Cells(Rows.Count, 1).End(xlUp).Row
             
    For x = 2 To Rows.Count
               
        If Cells(x, 2).Value > 0 Then
        
            Cells(x, 16).FormulaArray = "=IF(ISNA(INDEX('Plan Output'!R2C1:R" & LastRow4 & "C10,MATCH(1," & "R" & x & "C" & "2='Plan Output'!R2C1:R" & LastRow4 & "C1)*(R1C16='Plan Output'!R2C4:R" & LastRow4 & "C4),FALSE),6)),0," & _
                                            "F_F_F"
            Cells(x, 16).Replace "F_F_F", "INDEX('Plan Output'!R2C1:R" & LastRow4 & "C10,MATCH(1," & "R" & x & "C" & "2='Plan Output'!R2C1:R" & LastRow4 & "C1)*(R1C16='Plan Output'!R2C4:R" & LastRow4 & "C4),FALSE),6)))", lookat:=xlPart
                      
       End If
              
       Next x

End Sub[/SIZE][/FONT][/FONT]

Option 2

Code:
[FONT=courier new][SIZE=2]Sub CompleteHCData()

Dim LastRow4 As Long
Dim x As Long
Dim VAPP As Worksheet
Dim formulaMLA As String
Dim formulaMLA2 As String

   Set VAPP = ActiveWorkbook.Sheets("Plan Output")
   LastRow4 = VAPP.Cells(Rows.Count, 1).End(xlUp).Row

   For x = 2 To Rows.Count

          With Cells(x, 16)

               formulaMLA = "INDEX('Plan Output'!R2C1:R" & LastRow4 & "C10,MATCH(1," & "R" & x & "C" & "2='Plan Output'!R2C1:R" & LastRow4 & "C1)*(R1C16='Plan Output'!R2C4:R" & LastRow4 & "C4),FALSE),6)"
               formulaMLA2 = "INDEX('Plan Output'!R2C1:R" & LastRow4 & "C10,MATCH(1," & "R" & x & "C" & "2='Plan Output'!R2C1:R" & LastRow4 & "C1)*(R1C16='Plan Output'!R2C4:R" & LastRow4 & "C4),FALSE),6))))"

               .FormulaArray = "=IF(ISNA(""INDX1""),0,""INDX2"")"
               .Replace What:="INDX1", Replacement:=formulaMLA, lookat:=xlPart
               .Replace What:="INDX2", Replacement:=formulaMLA2, lookat:=xlPart

           End With

        End if

        Next x

End Sub[/SIZE]
[/FONT]

Ultimately, the formula supposed to be as below for every row in column 16...

Code:
[SIZE=2][FONT=courier new]{=IF(ISNA(INDEX('Plan Output'!R2C1:R62C10,MATCH(1,R2C2='Plan Output'!R2C1:R62C1)*(R1C16='Plan Output'!R2C4:R62C4),FALSE),6))),0,(INDEX('Plan Output'!R2C1:R62C10,MATCH(1,R2C2='Plan Output'!R2C1:R62C1)*(R1C16='Plan Output'!R2C4:R62C4),FALSE),6))))}[/FONT][/SIZE]

Any help / suggestions would be much appreciated.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Which sheet are you putting the array formula(s) on?
 
Upvote 0
I think there are errors in the formulas stored in formulaMLA and formulaMLA2 and it should just be "=IF(ISNA(INDX1),0,INDX2)"
 
Upvote 0
I think there are errors in the formulas stored in formulaMLA and formulaMLA2 and it should just be "=IF(ISNA(INDX1),0,INDX2)"
Did a check on the formula and compare them with the original ones and they looked fine... unless I have missed something out.

I have changed the formula to "=IF(ISNA(INDX1),0,INDX2)" but when I run macro, the cell will appear with this formula:

Code:
{=IF(ISNA(INDX),0,INDX2)}
 
Upvote 0

Forum statistics

Threads
1,214,635
Messages
6,120,660
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top