Macro to add a formula in a cell

zoog25

Active Member
Joined
Nov 21, 2011
Messages
418
Hello All,

Here is my situation, I have a macro that when a certain item is column "D". It formats several other columns in the same row that the information is being added. My situation is that part of the formatting is erasing information. The problem is that in column "AE" there is a specific formula. The following formula is added to the cell

=IF(AD3="N/A",EDATE(AC3,12),EDATE(AD3,12))

So my questions is how do i code so the above formula is inputed in column AE. Note that "AD3" is just where i copied the formula from. The number of the row is currently stored in Target.Row so it changes based on which row the formula is inputted.

Thanks for any help.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
.
Sheets("Sheet1").Range("F4").Value = "=IF(AD3=""N/A"",EDATE(AC3,12),EDATE(AD3,12))"

Edit the sheet name and the cell value as needed.

Note in the formula ... where there originally was one quotation mark .. there are now two.
 
Upvote 0
.. how do i code so the above formula is inputed in column AE. Note that "AD3" is just where i copied the formula from. The number of the row is currently stored in Target.Row so it changes based on which row the formula is inputted.
Try
Code:
Range("AE" & Target.Row).Formula = Replace("=IF(AD#=""N/A"",EDATE(AC#,12),EDATE(AD#,12))", "#", Target.Row)
 
Upvote 0
Thank you Logit and Peter for the help. I believe the Peter's replace method is what i was looking for so thank you.
 
Upvote 0
Thank you Logit and Peter for the help. I believe the Peter's replace method is what i was looking for so thank you.
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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