VBA - Executing array formulas

NathanA

New Member
Joined
Jan 18, 2017
Messages
34
Hello,

The code below was written to update formulas in F5:N and array formulas in H5:AA, and replace the formulas in F6:A6 and below with the output as values. I am using VBA code to avoid a slow workbook, forcing the formulas to run only after I have updated other data in the workbook.

The code updates the formulas correctly, however the array formulas in rows 6 and below return #N/A. I have searched online and tried adding Array to Formula (FormulaArray) however this returns an error message. I have checked possible reasons for this error and for example, the array formulas are less than the maximum 255 characters. Is it possible to amend the code below to successfully run the array formulas?

Code:
Option Explicit


Sub RefreshData()


'Declare variables
Dim desWS As Worksheet, i As Long, LastRow As Long


'Set the sheet
Set desWS = Sheets("View")


    With desWS
        LastRow = .Range("D" & .Rows.Count).End(xlUp).Row
        .Range("F6:AA" & .Rows.Count).ClearContents
        For i = 6 To 27
            Application.StatusBar = "Updating column " & i & " of 27"
            DoEvents
            
            .Range(.Cells(5, i), .Cells(LastRow, i)).Formula = .Cells(5, i).Formula
            .Range(.Cells(6, i), .Cells(LastRow, i)).Value = .Range(.Cells(6, i), .Cells(LastRow, i)).Value
        Next i
    End With
    
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Did you try this?

Code:
.Cells(5, i).Formula.Copy .Range(.Cells(5, i), .Cells(LastRow, i))
 
Upvote 0
What if you try
Code:
.Range(.Cells(5, i), .Cells(LastRow, i)).FillDown
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Just out of personal interest does the below work for you?

Code:
    Dim x As String
    x = .Cells(5, i).Formula
    With .Range(.Cells(5, i), .Cells(LastRow, i))
        .Formula = x
        .FormulaArray = .FormulaR1C1
    End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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