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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

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)"
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092

ADVERTISEMENT

Hello Andrew,

To_Day is a named cell reference, (Todays date)

In that case try onlyadrafter's solution.
 

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,136,649
Messages
5,676,991
Members
419,667
Latest member
MegEri

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