Vba for each cell in rng insert dynamic formula

Alpacino

Well-known Member
Joined
Mar 16, 2011
Messages
511
Hi all,

this might be simple but can’t get my head around it.

i would like to put a formula into each cell within a range (B2:AZ517)

Then paste the value then move onto the next cell.

The only thing is that the formula contains references e.g. row 1 and column A must stay constant.

for example the cell B2 would be Sum(B$1,$A2) moving onto next row
B3 cell would be Sum(B$1,$A3)

anyone help please.. ?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
This...

Code:
Sub test()


    Range("B2").Formula = "=sum(B$1,$A2)"
    Range("B2").AutoFill Range("B2:B517")
    
End Sub
 
Upvote 0
Hi igold

Many thanks for this, however I need to paste the values from the formula into each of cell before moving onto the next one, is this something you could help with ?.
 
Upvote 0
If I understand your requirement, does this do what you want...

Code:
Sub test()


    Dim arr
    Range("B2").Formula = "=sum(B$1,$A2)"
    Range("B2").AutoFill Range("B2:B517")
    arr = Range("B2:AZ517")
    Range("B2").Resize(UBound(arr, 1), UBound(arr, 2)) = arr
    
End Sub
 
Upvote 0
Try this:

Code:
Sub test1()
  Range("B2:AZ517").Formula = "=Sum(B$1,$A2)"
End Sub

If you need the values

Code:
Sub test1()
  With Range("B2:AZ517")
    .Formula = "=Sum(B$1,$A2)"
    .Value = .Value
  End With
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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