+ Reply to Thread
Results 1 to 3 of 3

Thread: Userform textbox to add data instead of replace it.

  1. #1
    Registered User
    Join Date
    01-06-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    14

    Userform textbox to add data instead of replace it.

    I have a spreadsheet which I want to use for sales recording/stock control, within it I have a userform with product references and textboxes so a user can enter the quantity sold of certain products. Data will go to two worksheets (WS1 as a historical record of sales, and WS2 as a running total). However with my current setup my userform will only replace the number in its assigned cell in WS2. What I want to do is make the userform add to the cell in WS2 so I can have a running total. Im hoping it's just a simple problem with a simple answer, here's my current code;

    Private Sub cmdAdd_Click()
        Dim iRow1 As Long
        Dim iRow2 As Long
        Dim WS1 As Worksheet, WS2 As Worksheet
        Set WS1 = Worksheets("RECORD")
        Set WS2 = Worksheets("COMPONENTS")
         
         'find first empty row in database
        iRow2 = WS2.Cells(Rows.Count, 2) _
        .End(xlUp).Offset(1, 0).Row
         
         'find first empty row in database
        iRow1 = WS1.Cells(Rows.Count, 2) _
        .End(xlUp).Offset(1, 0).Row
    
    
    
    'copy the data to the database "RECORD"
    
    WS1.Cells(iRow1, 1).Value = Me.TXTDATE
    WS1.Cells(iRow1, 2).Value = "DISPATCH"
    WS1.Cells(iRow1, 3).Value = "DOUBLE WIDTH 2.7M"
    WS1.Cells(iRow1, 4).Value = Me.DW32.Value
    WS1.Cells(iRow1, 5).Value = Me.DW37.Value
    WS1.Cells(iRow1, 6).Value = Me.DW42.Value
    WS1.Cells(iRow1, 7).Value = Me.DW47.Value
    WS1.Cells(iRow1, 8).Value = Me.DW52.Value
    WS1.Cells(iRow1, 9).Value = Me.DW57.Value
    WS1.Cells(iRow1, 10).Value = Me.DW62.Value
    WS1.Cells(iRow1, 11).Value = Me.DW67.Value
    WS1.Cells(iRow1, 12).Value = Me.DW72.Value
    WS1.Cells(iRow1, 13).Value = Me.DW77.Value
    WS1.Cells(iRow1, 14).Value = Me.DW82.Value
    WS1.Cells(iRow1, 15).Value = Me.DW87.Value
    WS1.Cells(iRow1, 16).Value = Me.DW92.Value
    WS1.Cells(iRow1, 17).Value = Me.DW97.Value
    WS1.Cells(iRow1, 18).Value = Me.DW102.Value
    WS1.Cells(iRow1, 19).Value = Me.DW107.Value
    WS1.Cells(iRow1, 20).Value = Me.DW112.Value
    WS1.Cells(iRow1, 21).Value = Me.DW117.Value
    WS1.Cells(iRow1, 22).Value = Me.DW122.Value
    WS1.Cells(iRow1, 23).Value = Me.DW127.Value
    WS1.Cells(iRow1, 24).Value = Me.DW132.Value
    WS1.Cells(iRow1, 25).Value = Me.DW137.Value
    WS1.Cells(iRow1, 26).Value = Me.DW142.Value
    
    
    'copy the data to the database "COMPONENTS"
    
    WS2.Range("D6").Value = Me.DW32.Value
    WS2.Range("E6").Value = Me.DW37.Value
    WS2.Range("F6").Value = Me.DW42.Value
    WS2.Range("G6").Value = Me.DW47.Value
    WS2.Range("H6").Value = Me.DW52.Value
    WS2.Range("I6").Value = Me.DW57.Value
    WS2.Range("J6").Value = Me.DW62.Value
    WS2.Range("K6").Value = Me.DW67.Value
    WS2.Range("L6").Value = Me.DW72.Value
    WS2.Range("M6").Value = Me.DW77.Value
    WS2.Range("N6").Value = Me.DW82.Value
    WS2.Range("O6").Value = Me.DW87.Value
    WS2.Range("P6").Value = Me.DW92.Value
    WS2.Range("Q6").Value = Me.DW97.Value
    WS2.Range("R6").Value = Me.DW102.Value
    WS2.Range("S6").Value = Me.DW107.Value
    WS2.Range("T6").Value = Me.DW112.Value
    WS2.Range("U6").Value = Me.DW117.Value
    WS2.Range("V6").Value = Me.DW122.Value
    WS2.Range("W6").Value = Me.DW127.Value
    WS2.Range("X6").Value = Me.DW132.Value
    WS2.Range("Y6").Value = Me.DW137.Value
    WS2.Range("Z6").Value = Me.DW142.Value
    
    'clear the data
    Me.TXTDATE.Value = ""
    Me.DW32.Value = ""
    Me.DW37.Value = ""
    Me.DW42.Value = ""
    Me.DW47.Value = ""
    Me.DW52.Value = ""
    Me.DW57.Value = ""
    Me.DW62.Value = ""
    Me.DW67.Value = ""
    Me.DW72.Value = ""
    Me.DW77.Value = ""
    Me.DW82.Value = ""
    Me.DW87.Value = ""
    Me.DW92.Value = ""
    Me.DW97.Value = ""
    Me.DW102.Value = ""
    Me.DW107.Value = ""
    Me.DW112.Value = ""
    
    Me.DW117.Value = ""
    Me.DW122.Value = ""
    Me.DW127.Value = ""
    Me.DW132.Value = ""
    Me.DW137.Value = ""
    Me.DW142.Value = ""
    
    Me.DW142.SetFocus
    
    End Sub
    Any help will be really appreciated, thanks.
    Last edited by BPSJACK; 02-07-2012 at 12:28 PM.

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Userform textbox to add data instead of replace it.

    Try this
    WS2.Range("D6").Value = WS2.Range("D6").Value + CInt(Me.DW32.Value)
    'etc
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Registered User
    Join Date
    01-06-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Userform textbox to add data instead of replace it.

    Worked a treat thankyou for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0