Results 1 to 3 of 3

insert a vba Formula to a column an comand button

Threaded View

  1. #1
    Registered User
    Join Date
    01-08-2012
    Location
    Lx, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    2

    Unhappy insert a vba Formula to a column an comand button

    Hello

    I have a table where random records that are automatically inserted when you press the command button 1, with your help I managed to set all columns exept the last column (column O) because I don't kno what shall i do to enter the following formula: = (L7 -SOMA.SE (D7: N7, D7; K7: K7)) + SOMA.SE (D7: N7, D7, N7, N7)

    this formula should be inserted in the button code in order to automatically calculate the value of O7 after that when i press the button he must calculate O8 and so on.
    it is important to gradually increase the formula references cells +1, so it would be for the cell:
    O7 -> = (L7-SOMA.SE (D7: N7, D7; K7: K7)) + SOMA.SE (D7: N7, D7, N7, N7)

    cell O8 -> = (L8-(SOMA.SE (D7: N8, D8, K7, K8)) + SOMA.SE (D7: N8, D8, N7, N8))


    cell O9 -> = (L9-(SOMA.SE (D7: N9, D9, K7, K9)) + SOMA.SE (D7: N9, D9, N7, N9))

    10 cell -> = (L10-(SOMA.SE (D7: N10, D10, K7: K10)) + SOMA.SE (D7: N10, D10, N7, N10))

    and so on

    already have my button the following code:

    Private Sub CommandButton1_Click ()
    
    Range ("c65536"). End (xlUp). Offset (1, 0). Select
    ActiveCell = Now
    
    
    Range ("d65536"). End (xlUp). Offset (1, 0). Select
    ActiveCell = Range ("d4"). Value
    
    Range ("k65536"). End (xlUp). Offset (1, 0). Select
    ActiveCell = Range ("i4"). Value
    
    Range ("n65536"). End (xlUp). Offset (1, 0). Select
    ActiveCell = Range ("i2"). Value
    
    Range ("f65536"). End (xlUp). Offset (1, 0). Select
    ActiveCell.FormulaR1C1 = "= VLOOKUP (RC4, Drugs! R3C2: R402C8, 2, FALSE)"
    
    Range ("l65536"). End (xlUp). Offset (1, 0). Select
    ActiveCell.FormulaR1C1 = "= VLOOKUP (RC4, Drugs! R3C2: R402C8, 3, FALSE)"
    
    Range ("m65536"). End (xlUp). Offset (1, 0). Select
    ActiveCell.FormulaR1C1 = "= VLOOKUP (RC4, Drugs! R3C2: R402C8, 4, FALSE)"
    
    End Sub
    Any ideas? I really need you Help.
    Last edited by Paul; 01-08-2012 at 09:30 PM. Reason: Added code tags for new user. Please do so yourself in the future.

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