Using VB to paste a function into a cell

moheganburner

Board Regular
Joined
Dec 2, 2005
Messages
158
Is it possible to use VB to paste a function into a cell? I tried to do it literally, i.e.:

Code:
Sub Paste()

Sheets("Sheet3").Range("A:A65536").Function = "=TRIM(IF(COUNTIF(B1:C1,"*Joe*"),"Pay","")&" "&IF(SUM(COUNTIF(D1:E1,{"*Scott*","*Frank*","*Pete*"})),"Fire",""))&" "&IF(COUNTIF(F1:G1,"*Tim*"),"Raise","")"

End Sub

but I think all the quotations are a problem.

Thanks,
MB
 

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".
Hi there

The best way to get a formula into code is to use the macro recorder.
First type in the formula on your worksheet and ensure it is returning the answer correctly. Start the macro recorder, select the cell with the formula, delete the = sign then reinsert it and press Enter. Stop the recorder and check out the code in the VB editor (Alt+F11).

If you have a scrollable formula (ie the formula in A1 can be scrolled right to column Z and down to row 500), record the formula in A1 as above then modify the code in the VB Editor to change the range ... eg Range("A1:Z500")

regards
Derek
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

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