banner



How To Put A Formula Into A Cell Vba

  • Remove From My Forums

 locked

How to insert IF role using VBA

  • Question

  • I take this IF-function i would like to create in VBA and paste into a prison cell of an excel canvass: =IF(C7="Innkommende";S7+T8;0)

    I accept this little test procedure:

    Individual Sub CommandButton1_Click()
    MsgBox ("=IF(C7=" & """" & "Innkommende" & """" & ";S7+T8;0)")
    Cells(4, 22).Value = "IF(C7=" & """" & "Innkommende" & """" & ";S7+T8;0)" 'Writes the text to a cell
    Cells(2, 22).Formula = "=IF(C7=" & """" & "Innkommende" & """" & ";S7+T8;0)"
    Range("V2").Formula = "=IF(C7=" & """" & "Innkommende" & """" & ";S7+T8;0)"
    Cease Sub

    1st line with msgbox works ok

    2nd line works ok, I get a text into a cell. I become to this cell and manually write the equal sign = in front, and the formula behaves as expected.

    The next two lines do not piece of work at all. I get run fourth dimension error '1004' Application-defined or object-defined error. All cells used by the formula have stable data, text in cell C7 and figures in cells T7 and S8. What is wrong here?

    Regards from Tore


    Tore

Answers

  • Y'all could read almost .formulalocal in VBA's assistance, besides.

    Dave Peterson wrote:

    Excel's VBA is USA centric.  You lot'll want to use comma equally the list separator in
    your formula:

    Choice Explicit
    Individual Sub CommandButton1_Click()
    Dim myFormula Equally Cord
    myFormula = "=IF(C7=""Innkommende"",S7+T8,0)"
    Me.Cells(4, 22).Formula = myFormula
    End Sub

    Tore572 wrote:

    I take this IF-function i would like to create in VBA and paste into a jail cell of an excel sheet: =IF(C7="Innkommende";S7+T8;0)

    I accept this little test procedure:

    Individual Sub CommandButton1_Click()
    MsgBox ("=IF(C7=" & """" & "Innkommende" & """" & ";S7+T8;0)")
    Cells(iv, 22).Value = "IF(C7=" & """" & "Innkommende" & """" & ";S7+T8;0)" 'Writes the text to a prison cell
    Cells(ii, 22).Formula = "=IF(C7=" & """" & "Innkommende" & """" & ";S7+T8;0)"
    Range("V2").Formula = "=IF(C7=" & """" & "Innkommende" & """" & ";S7+T8;0)"
    End Sub

    1st line with msgbox works ok

    2nd line works ok, I get a text into a prison cell. I go to this prison cell and manually write the equal sign = in front, and the formula behaves every bit expected.

    The next two lines do not work at all. I get run time error '1004' Application-defined or object-defined fault. All cells used by the formula take stable data, text in cell C7 and figures in cells T7 and S8. What is wrong here?

    Regards from Tore

    --
    Tore

    --

    Dave Peterson

    • Marked every bit answer by Thursday, October 28, 2010 five:56 PM

How To Put A Formula Into A Cell Vba,

Source: https://social.msdn.microsoft.com/Forums/office/en-US/c6b1dc94-b171-49f0-9c20-d3860a70a22c/how-to-insert-if-function-using-vba

Posted by: aldrichtrepen.blogspot.com

0 Response to "How To Put A Formula Into A Cell Vba"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel