+ Reply to Thread
Results 1 to 7 of 7

How to insert a complex formula in a cell with VBA

  1. #1
    mircea
    Guest

    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. #2
    Frank Kabel
    Guest

    Re: How to insert a complex formula in a cell with VBA

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

    --
    Regards
    Frank Kabel
    Frankfurt, Germany
    "mircea" <cupidon@email.com> schrieb im Newsbeitrag
    news:OkLGHRn8EHA.1392@tk2msftngp13.phx.gbl...
    > 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. #3
    Peo Sjoblom
    Guest

    RE: How to insert a complex formula in a cell with VBA

    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. #4
    mircea
    Guest

    Re: How to insert a complex formula in a cell with VBA

    thanks a lot !



  5. #5
    Dana DeLouis
    Guest

    Re: How to insert a complex formula in a cell with VBA

    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" <cupidon@email.com> wrote in message
    news:OkLGHRn8EHA.1392@tk2msftngp13.phx.gbl...
    > 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. #6
    Ken
    Guest

    RE: How to insert a complex formula in a cell with VBA

    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. #7
    mircea
    Guest

    Re: How to insert a complex formula in a cell with VBA

    thanks again to all of you !
    Very helpfull newsgroup.



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1