How to insert formulas into cells using vba loops

Waimea

Active Member
Joined
Jun 30, 2018
Messages
465
Office Version
  1. 365
Platform
  1. Windows
I am really struggling with how to insert formulas in cells using VBA and loops and it would be very kind if someone can show me an example of how to insert different formulas in different columns.

I would like to learn so that I can use this in my workbooks.

Row1 contains headers from A1 to G1.

Row2 to row10 contains randbetween(0,10) in the Range(A2:E10)

I would like to use some kind of loop to insert the following formulas in these cells.

Code:
Formula#1 ="SUM(A2:A10)"

Formula#2 ="AVERAGE(A2:E10)"

Formula#3 = =SUMPRODUCT($B$2:$E$2;B2:E2)



I am trying to get formula#1 in column F in the range of F2:F10 and formula#2 in column G in the range of G2:G10 and formula#3 in column H.
 
Last edited:
Look at my comment 11 and apply it!!
Starting from my code in comment 16 change sumproduct to SQRT etc, and then the only problem is where to insert the 2nd *SQRT, so pick somewhere and try it. Remember that every time you add something to the middle of an existing string you must surround it with ampersands (&)
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,215,329
Messages
6,124,301
Members
449,149
Latest member
mwdbActuary

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