Pasting formulas to a cell using VB

odggi

New Member
Joined
Sep 3, 2006
Messages
4
Hello all,

I am trying to copy this formula to a cell in VB but i keep getting an error:

Dim sFormu as string
sFormu = "=IF(ISERROR(AD2+To_Day),"",AD2+To_Day)"
Range("B20").Value = sFormu

What an I doing wrong?

Thanking you all in advance.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
What's To_Day? A variable?

sFormu = "=IF(ISERROR(AD2+" & To_Day & "),"""",AD2+" & To_Day & ")"
 

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
Hello

try

Code:
Range("B20").Formula = "=IF(ISERROR(AD2+To_Day),"""",AD2+To_Day)"
 

odggi

New Member
Joined
Sep 3, 2006
Messages
4
Hello Only a Drafter

I have tried your method, but it still gave me a runtime error.
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Hello Only a Drafter

I have tried your method, but it still gave me a runtime error.

I tried it too and B20 had the formula:

=IF(ISERROR(AD2+To_Day),"",AD2+To_Day)
 

odggi

New Member
Joined
Sep 3, 2006
Messages
4
Hello All, I've tried it on a different pc, and its worked, so thanks again.
 

Forum statistics

Threads
1,172,017
Messages
5,878,755
Members
433,370
Latest member
mcleven

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
Top