Load a Dynamic formula using vba

RobP

Well-known Member
Joined
May 8, 2008
Messages
847
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have a list of peoples names in column C, and some numbers alongside in columns D, F and H. (cols E, G and I contain text data).

The list of names is generated elsewhere, and varies in size (sometimes it could be 5 names in the list, other times it could have 20 names in the list etc.)

In column G, I want to insert a "TOTAL" formula, to sum cols D, F and H, using VBA - as I cant preload the formula, not knowing the size of list beforehand. (Sure I could load the complete column before with formula, but thats a little lame ;) if I only have 5 entries.)

Any ideas on the syntax to be used for inserting a dynamic formula into a cell ?

x = row number

Range("G" & x).Formula =

Thanks
Rob
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try

Code:
Range("G" & x).Formula = "=SUM(D" & x & ",F" & x & ",H" & x & ")"
 
Upvote 0
Many thanks .... that works perfectly ... I couldn't suss out where my "" were supposed to be.
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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