Consulting

Results 1 to 6 of 6

Thread: Problem with Changing formula

  1. #1
    VBAX Newbie
    Joined
    Mar 2011
    Posts
    3
    Location

    Angry Problem with Changing formula

    Hello
    I want to change a cell formula when a button pressed and The formula must have an if statement!
    I have tried this code but an 1004 error occurs.

    [VBA]Private Sub CommandButton1_Click()
    t = "=IF(5>=2;1;7)"
    Cells(1, 1) = t
    End Sub[/VBA]

    thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub CommandButton1_Click()
    Cells(1, 1).Formula = "=IF(5>=2,1,7)"
    End Sub[/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Mar 2011
    Posts
    3
    Location
    Quote Originally Posted by xld
    [vba]

    Private Sub CommandButton1_Click()
    Cells(1, 1).Formula = "=IF(5>=2,1,7)"
    End Sub[/vba]
    Thank you very much It worked.
    But I have still Problem!
    can you test my sheet?(I have attached)

    Thanks
    Attached Files Attached Files

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    And the problem is ...?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Newbie
    Joined
    Mar 2011
    Posts
    3
    Location
    Quote Originally Posted by xld
    And the problem is ...?
    The Problem is that 1004 error occurs!

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I give you a solution, you say it worked, and then you say you still have a problem, even though it is with another piece of code which you didn't present before and ignored the solution I previously gave. Sheesh!

    [vba]

    Private Sub CommandButton1_Click()
    Dim i As Integer
    i = 12
    t = "=IF(SUM(F8:F" + Trim(Str(i)) + ")>=K5,K5-I5,IF(SUM(F8:F" + Trim(Str(i)) + ")>=I5,SUM(F8:F" + Trim(Str(i)) + ")-I5,0))"
    Cells(1, 1).Formula = t

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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