VBA instead of array formulae

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,926
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Is it possible to replace array formulae with just VBA?

If I have the data as follows:

Rich (BB code):
1    10
2    25
3    30

and I want to sum column A and put the result in cell D1, I can record a macro to generate this code:

Rich (BB code):
Range("D1").Select
    ActiveCell.FormulaR1C1 = "=SUM(RC[-3]:R[2]C[-3])"



Alternatively I can wite:

Rich (BB code):
Range("D1").Value = Range("A1").Value+Range("A2").Value+Range("A3").Value


If on the other hand I want to use the LINEST function, the recorded macro shows:

Rich (BB code):
Range("F1:G1").Select
    Selection.FormulaArray = "=LINEST(RC[-4]:R[2]C[-4],RC[-5]:R[2]C[-5])"



How can I rewrite this so the formula is NOT shown in Excel?

Thanks

<strike>
</strike>
<strike>
</strike>
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try
Code:
Range("F1:G1").Select
With Selection
    .FormulaArray = "=LINEST(RC[-4]:R[2]C[-4],RC[-5]:R[2]C[-5])"
    .Value = .Value
End With
 
Upvote 0
Hi, maybe:

Code:
Range("F1:G1").Value = Evaluate("LINEST(B1:B3,A1:A3)")
 
Upvote 0
Hi there. You could add this code straight after:
Code:
Selection.Value = Selection.Value
Just make sure automatic calculation is on.
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

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