PC Review


Reply
Thread Tools Rate Thread

cell formula in string variable doesnt work

 
 
James
Guest
Posts: n/a
 
      8th Jul 2009

I have:
Y1 = "=IF($D24=0,"",$D24-$I$4*TAN(RADIANS(L10)/2))"
Y2 = "=IF($D24=0,"",$D24-$I$4*2*TAN(RADIANS(L10)/2))"

then try and use:
Range("J10").Select
ActiveCell.FormulaR1C1 = Y1
Range("J11").Select
ActiveCell.FormulaR1C1 = Y2

Why doesnt this work?
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      8th Jul 2009
Hi,

Try this and note the doubled up internal quotes in the formula

Y1 = "=IF($D24=0,"""",$D24-$I$4*TAN(RADIANS(L10)/2))"
Y2 = "=IF($D24=0,"""",$D24-$I$4*2*TAN(RADIANS(L10)/2))"
Range("J10").Formula = Y1
Range("J11").Formula = Y2

Mike

"James" wrote:

> I have:
> Y1 = "=IF($D24=0,"",$D24-$I$4*TAN(RADIANS(L10)/2))"
> Y2 = "=IF($D24=0,"",$D24-$I$4*2*TAN(RADIANS(L10)/2))"
>
> then try and use:
> Range("J10").Select
> ActiveCell.FormulaR1C1 = Y1
> Range("J11").Select
> ActiveCell.FormulaR1C1 = Y2
>
> Why doesnt this work?

 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      8th Jul 2009

On Wed, 8 Jul 2009 10:45:01 -0700, James <(E-Mail Removed)>
wrote:

>I have:
>Y1 = "=IF($D24=0,"",$D24-$I$4*TAN(RADIANS(L10)/2))"
>Y2 = "=IF($D24=0,"",$D24-$I$4*2*TAN(RADIANS(L10)/2))"
>
>then try and use:
>Range("J10").Select
>ActiveCell.FormulaR1C1 = Y1
>Range("J11").Select
>ActiveCell.FormulaR1C1 = Y2
>
>Why doesnt this work?


1. Your string is not producing what you think it is. When VBA sees a double
quote within quotes, it translates that as a single quote. So your Y1 string
comes out as

=IF($D24=0,",$D24-$I$4*TAN(RADIANS(L10)/2))

If you want it to come out correctly, you need to have TWO (2) double quotes:
ie.

y1 = "=IF($D24=0,"""",$D24-$I$4*TAN(RADIANS(L10)/2))"

2. You are using the FormulaR1C1 of the Range object, but your formula is not
in that form -- it does not have an R1C1 style references.

You can either change your formula to use R1C1 style references; or use the
Formula property of the Range object.
--ron
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Coercion of a String Into a Double Doesnt work (??!!) AGP Microsoft VB .NET 9 29th Aug 2008 01:13 AM
Help!!! Formula doesnt work. =?Utf-8?B?UmVzcG9uc2UgdG8gbmVzdGluZyBwcm9ibGVt?= Microsoft Excel Programming 3 10th Nov 2007 05:56 AM
Formula doesnt work when copy in different cell =?Utf-8?B?TWF0?= Microsoft Excel Misc 3 20th Apr 2007 08:34 PM
IF AND MID FORMULA DOESNT WORK-WHY?? =?Utf-8?B?U29jYWwgQW5hbHlzdCBsb29raW5nIGZvciBoZWxw Microsoft Access Queries 6 19th Apr 2006 12:44 PM
Formula doesnt work =?Utf-8?B?S2V2aW4=?= Microsoft Excel Worksheet Functions 2 24th Feb 2005 12:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:12 PM.