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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,223,887
Messages
6,175,199
Members
452,617
Latest member
Narendra Babu D

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