Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Setting a cell's formula with VBA

I have a cell defined with the following formula

=IF($E$5="SHP", IF(K8="skid", J8*I8/1000*H8, J8*I8*H8 ), "" )

My intent is to use the formaula to provide a calucated estimate based on
the values of cells E5 and K8. The user would then be free to accept the
estimate, or to revise it. The problem is that when the value is changed,
the formula is lost! So, I am attempting to add the formula to the cell
via a macro. I have tried numerous combinations concatenating quotes and
strings but cannot seem to get it right. What visually looks good yields
compiler errors like missing end of statement. What satisfies the
compiler, corrupts the above formula's intent. Any and all suggestions
would be greatly appreciated. Thanks in advance!

Here is what I currently have that is giving the error - Compile error:
Expected: end of statement

Range("L8").Formula = "IF($E$5="SHP", IF(K8="skid",
J8*I8/1000*H8, J8*I8*H8 ), "" )"


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Setting a cell's formula with VBA

Try this

Range("L8").Formula = "=IF($E$5=""SHP"", IF(K8=""skid"", J8*I8/1000*H8,
J8*I8*H8 ), """" )"

--

HTH

RP
(remove nothere from the email address if mailing direct)


wrote in message
...
I have a cell defined with the following formula

=IF($E$5="SHP", IF(K8="skid", J8*I8/1000*H8, J8*I8*H8 ), "" )

My intent is to use the formaula to provide a calucated estimate based on
the values of cells E5 and K8. The user would then be free to accept the
estimate, or to revise it. The problem is that when the value is changed,
the formula is lost! So, I am attempting to add the formula to the cell
via a macro. I have tried numerous combinations concatenating quotes and
strings but cannot seem to get it right. What visually looks good yields
compiler errors like missing end of statement. What satisfies the
compiler, corrupts the above formula's intent. Any and all suggestions
would be greatly appreciated. Thanks in advance!

Here is what I currently have that is giving the error - Compile error:
Expected: end of statement

Range("L8").Formula = "IF($E$5="SHP", IF(K8="skid",
J8*I8/1000*H8, J8*I8*H8 ), "" )"




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Setting a cell's formula with VBA

..Formula = "=IF($E$5=""SHP"", IF(K8=""skid"", J8*I8/1000*H8, J8*I8*H8 ),
"""" )"

Tested in the Immediate window:

? "=IF($E$5=""SHP"", IF(K8=""skid"", J8*I8/1000*H8, J8*I8*H8 ), """" )"
=IF($E$5="SHP", IF(K8="skid", J8*I8/1000*H8, J8*I8*H8 ), "" )

--
Regards,
Tom Ogilvy



wrote in message
...
I have a cell defined with the following formula

=IF($E$5="SHP", IF(K8="skid", J8*I8/1000*H8, J8*I8*H8 ), "" )

My intent is to use the formaula to provide a calucated estimate based on
the values of cells E5 and K8. The user would then be free to accept the
estimate, or to revise it. The problem is that when the value is changed,
the formula is lost! So, I am attempting to add the formula to the cell
via a macro. I have tried numerous combinations concatenating quotes and
strings but cannot seem to get it right. What visually looks good yields
compiler errors like missing end of statement. What satisfies the
compiler, corrupts the above formula's intent. Any and all suggestions
would be greatly appreciated. Thanks in advance!

Here is what I currently have that is giving the error - Compile error:
Expected: end of statement

Range("L8").Formula = "IF($E$5="SHP", IF(K8="skid",
J8*I8/1000*H8, J8*I8*H8 ), "" )"




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Setting a cell's formula with VBA

Hi

Add an equal sign between the "and IF($E$5.... i.e.

Range("L8").Formula = "=IF($E$5="SHP", IF(K8="skid",
J8*I8/1000*H8, J8*I8*H8 ), "" )"

Also another way , if the formula is working OK, start your macro recorder,
select cell L8 then Insert Function OK and stop recorder.
locate the recorded macro, cut and paste the line or lines into your code.
Note! Code will be in R1C1 format.

Regards
Bob C.


" wrote:

I have a cell defined with the following formula

=IF($E$5="SHP", IF(K8="skid", J8*I8/1000*H8, J8*I8*H8 ), "" )

My intent is to use the formaula to provide a calucated estimate based on
the values of cells E5 and K8. The user would then be free to accept the
estimate, or to revise it. The problem is that when the value is changed,
the formula is lost! So, I am attempting to add the formula to the cell
via a macro. I have tried numerous combinations concatenating quotes and
strings but cannot seem to get it right. What visually looks good yields
compiler errors like missing end of statement. What satisfies the
compiler, corrupts the above formula's intent. Any and all suggestions
would be greatly appreciated. Thanks in advance!

Here is what I currently have that is giving the error - Compile error:
Expected: end of statement

Range("L8").Formula = "IF($E$5="SHP", IF(K8="skid",
J8*I8/1000*H8, J8*I8*H8 ), "" )"



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
can I do a formula to use only the highlited cell's ekkeindoha Excel Worksheet Functions 1 May 7th 07 10:08 PM
How do I use a referenced cell's formula instead of formula output? Farrelltw Excel Worksheet Functions 0 February 10th 06 05:00 PM
Setting the magnification to a range of cell's ceemo Excel Discussion (Misc queries) 3 August 19th 05 01:53 PM
How do I use a cell's text, "A1", and put it in a formula? HighRiser Excel Worksheet Functions 1 July 6th 05 04:11 PM
Formula that will allow you to add one to cell's value by clickin. lb Excel Worksheet Functions 1 April 21st 05 06:20 PM


All times are GMT +1. The time now is 02:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"