• Running total from userform textbox (2K)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Running total from userform textbox (2K)

    Author
    Topic
    #384721

    A user selects from a combobox on a userform a particular department. The user then types in a value into a textbox. I am using this code to add the value to a worksheet to produce a running total. The worksheet contains 2 columns . My problem is that the value is always added to B2 irrespective of the department chosen. B2 represents the runnning total for the first item in the combobox. I’ve done this many times without problems but for some reason I cannot see what the problem is. Help please.

    Dim DepAC As Range
    Set DepAC = Worksheets(“Sheet1”).Range(“A2:A43”)
    DepAC.Find (ComboBox1.Value)
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = ActiveCell.Value + TextBox1.Value
    ‘ Clear the Text Box
    TextBox1.Value = “”

    Viewing 1 reply thread
    Author
    Replies
    • #660986

      False alarm! I realise that I must add after the method. However, I’m having difficulty in clearing the text box on opening the form. In the Workbook_Open event I am using:

      TextBox1.Value = “”

      but the text box always displays 6.35 each time I open the workbook. Any ideas?

    • #661114

      Your code can be shortened to:

      Dim DepAC As Range
      dim oFoundcell as range
      Set DepAC = Worksheets(“Sheet1”).Range(“A2:A43”)
      set ofoundcell=DepAC.Find(ComboBox1.Value).Offset(0, 1)
      ofoundcell.Value = ofoundCell.Value + TextBox1.Value
      ‘ Clear the Text Box
      TextBox1.Value = “”

      • #661242

        Much more elegant code. Thanks, Jan Karel – very useful.

    Viewing 1 reply thread
    Reply To: Running total from userform textbox (2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: