Insert the same same if statement in many cells with different formulas

brubru24

New Member
Joined
May 29, 2011
Messages
12
Hi,

I have many cells each with different formulas for example:

A1=G14/(1-$J$1)
A2=G15/(1-$J$1)
A3=G16/(1-$J$1)
A4=G17/(1-$J$1)

What I would like to do is to quickly insert the same if statement or at least partially in each cell above without having to change the pre-existing formula like below:

A1=If(B3="Yes",G14/(1-$J$1),0)
A2=If(B3="Yes",G15/(1-$J$1),0)
A3=If(B3="Yes",G16/(1-$J$1),0)
A4=If(B3="Yes",G17/(1-$J$1),0)


I hope it makes sense and thank you in advance for your help.

Kind regards,

Bruno
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try it as

=If(B$3="Yes",G14/(1-$J$1),0)

In A1, then copy it to the rest of the cells.
 
Upvote 0
Thank you.

I should have been more specific in my original request. I didn't mention that each cell has a different not linear formula so for example:

=If(B3="Yes",G27/(1-$J$1),0)
=If(B3="Yes",X28/(1-$J$1),0)
=If(B3="Yes",G30,0)

Thank you.Bruno
 
Upvote 0
This small piece of vba will apply the change to the selected cells, this is based on your examples, if you need variations then that will need to be allowed for.

Code:
Sub replaceformula()
Dim c As Range
For Each c In Selection
    c.Formula = "=IF(B$3=""Yes""," & Mid(c.Formula, 2, Len(c.Formula)) & ",0)"
Next
End Sub
 
Upvote 0
Deleted - incorrect answer
 
Last edited:
Upvote 0
This small piece of vba will apply the change to the selected cells, this is based on your examples, if you need variations then that will need to be allowed for.

Rich (BB code):
Sub replaceformula()
Dim c As Range
For Each c In Selection
    c.Formula = "=IF(B$3=""Yes""," & Mid(c.Formula, 2, Len(c.Formula)) & ",0)"
Next
End Sub
Jason, note that in vba the third argument for mid is not required if you want the whole rest of the string. So the red part can be omitted here.
 
Upvote 0
Jason, note that in vba the third argument for mid is not required if you want the whole rest of the string. So the red part can be omitted here.

Thanks Peter, I wasn't aware of that, I just use the same method as I would if it was a worksheet formula.
 
Upvote 0
Thanks Peter, I wasn't aware of that, I just use the same method as I would if it was a worksheet formula.
No problem. I like this shortened option and wish the worksheet function worked this way as well. :)
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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