Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
mircea
 
Posts: n/a
Default How to insert a complex formula in a cell with VBA

How to insert a formula in a cell with VBA
example : if formula is "=if(a3=2;a3;a2)"
i used
cells(2,3).Formula="=if(a3=2;a3;a2)"

bu i receive an error
Application object ....

if i used "=s4"
everything is ok.


  #2   Report Post  
Frank Kabel
 
Posts: n/a
Default

Hi
try:
cells(2,3).Formula="=if(a3=2,a3,a2)"

--
Regards
Frank Kabel
Frankfurt, Germany
"mircea" schrieb im Newsbeitrag
...
How to insert a formula in a cell with VBA
example : if formula is "=if(a3=2;a3;a2)"
i used
cells(2,3).Formula="=if(a3=2;a3;a2)"

bu i receive an error
Application object ....

if i used "=s4"
everything is ok.




  #3   Report Post  
Peo Sjoblom
 
Posts: n/a
Default

Use

Cells(2, 3).Formula = "=IF(a3=2,a3,a2)"


Regards,

Peo Sjoblom

"mircea" wrote:

How to insert a formula in a cell with VBA
example : if formula is "=if(a3=2;a3;a2)"
i used
cells(2,3).Formula="=if(a3=2;a3;a2)"

bu i receive an error
Application object ....

if i used "=s4"
everything is ok.



  #4   Report Post  
mircea
 
Posts: n/a
Default

thanks a lot !


  #5   Report Post  
Dana DeLouis
 
Posts: n/a
Default

Just a technique would be to place the equation into a cell manually just to
have Excel take a look at it.
If Excel doesn't complain, then copy the formula back into the macro. In a
more complicated statement, Excel might correct any missing '( ' or ')' .
Excel will correct any small letters like 'if' and 'a1' to the proper case
if all checks out.

Cells(2, 3).Formula = "=IF(A3=2,A3,A2)"

Again, just a technique.
--
Dana DeLouis
Win XP & Office 2003


"mircea" wrote in message
...
How to insert a formula in a cell with VBA
example : if formula is "=if(a3=2;a3;a2)"
i used
cells(2,3).Formula="=if(a3=2;a3;a2)"

bu i receive an error
Application object ....

if i used "=s4"
everything is ok.






  #6   Report Post  
Ken
 
Posts: n/a
Default

Something I just learned - you can use a more "direct" code to do this using
"Iif."

Cells(2, 3) = IIf(Cells(3, 1) = 2, Cells(3, 1), Cells(2, 1))


"mircea" wrote:

How to insert a formula in a cell with VBA
example : if formula is "=if(a3=2;a3;a2)"
i used
cells(2,3).Formula="=if(a3=2;a3;a2)"

bu i receive an error
Application object ....

if i used "=s4"
everything is ok.



  #7   Report Post  
mircea
 
Posts: n/a
Default

thanks again to all of you !
Very helpfull newsgroup.


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
inserting data from a row to a cell, when the row number is specified by a formula in a cell [email protected] New Users to Excel 2 January 6th 05 07:18 AM
using content of a cell in a formula in another cell mpierre Excel Worksheet Functions 3 December 28th 04 03:43 PM
How can I write an if-then formula for 0 or less than 0 in cell t. Baz1 Excel Worksheet Functions 1 November 30th 04 04:33 PM
GET.CELL Biff Excel Worksheet Functions 2 November 24th 04 07:16 PM
Cell doesn't show formula result - it shows formula (CTRL + ' doe. o0o0o0o Excel Worksheet Functions 6 November 19th 04 03:13 PM


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

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

About Us

"It's about Microsoft Excel"