Execute different formulas based on conditions

deduwa

Board Regular
Joined
Jul 28, 2015
Messages
110
I have the below code in Sheet1;

Cells(lastRow + 10, "R").FormulaR1C1 = "=R[-4]C+R[-4]C[-3]"

How can I adjust this such that;

- If cell F1 in the 'Man' worksheet = 1 then Cells(lastRow + 10, "R").FormulaR1C1 = "=R[-4]C+R[-4]C[-3]"

- If cell F1 in the 'Man' worksheet <> 1 then Cells(lastRow + 10, "R").FormulaR1C1 = "=R[-4]C"

Thanks
 

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".
Try:

Cells(lastRow + 10, "R").FormulaR1C1 = "=R[-4]C" & IIf(Sheets("Man").Range("F1").Value = 1,"+R[-4]C[-3]","")
 
Last edited:
Upvote 0
Does this work?

Code:
If Worksheets("Man").Range("F1")=1 Then
    Cells(lastRow + 10, "R").FormulaR1C1 = "=R[-4]C + R[-4]C[-3]"
Else
    Cells(lastRow + 10, "R").FormulaR1C1 = "=R[-4]C"
 
Upvote 0
As alt suggestion only, default all formula to be "=R[-4]C" and then only change if F1 from sheets Man = 1
Rich (BB code):
Cells(lastRow + 10, "R").FormulaR1C1 = "=R[-4]C"
If Worksheets("Man").cells(1,6).Value = 1 Then Cells(lastRow + 10, "R").FormulaR1C1 = "=R[-4]C + R[-4]C[-3]"
It's kinda combined suggestion from #2 and #3 but all should do as you need.

For #2 , I think @Eric W forgot an "=", i.e.
Rich (BB code):
Cells(lastRow + 10, "R").FormulaR1C1 = "=R[-4]C" & Iif(Sheets("Man").Range("F1").Value = 1,"+R[-4]C[-3]","")
 
Last edited:
Upvote 0
Clever cloggs, now my post is forever locked as implying yours has an error, even though it was editted to correct! :-p
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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