Can This Be Simplified

msfatman

Board Regular
Joined
Apr 10, 2008
Messages
110
I'm using code similar to this to enter some formula's:-

Code:
Sub test()
With Range("D2:D28008")
    .Formula = "=B2*C2"
    .Value = .Value
End With
 
With Range("E2:E28008")
    .Formula = "=vlookup(B2,TestData,5,false)"
    .Value = .Value
End With
 
With Range("F2:F28008")
    .Formula = "=B2*A2+3.658"
    .Value = .Value
End With
End Sub

In reality I'm populating 25 columns (different formulas) using this method which means I'm repeating the same piece of code.

I was wondering if there was a simpler way?
 
Last edited by a moderator:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi, you'll need to alter the ranges and formulas i have inputted below which i used to test run the code.

Code:
Sub test()

Dim arrrange
Dim arrformula

arrrange = Array("D2:D10", "E2:E10", "F2:F10")
arrformula = Array("=B2*C2", "=A2*C2", "=D2*C2")
   
   For i = LBound(arrrange) To UBound(arrrange)
        With Range(arrrange(i))
              .Formula = arrformula(i)
              .Value = .Value
        End With
   Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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