Hi,
I have a userform with a few textboxes and comboboxes some that self populate from a data base, what I need it to do is if they select OUT from combobox 1 the textbox self populates from a database they then choose an amount from the combobox 2 lets say 5 then when the command button is clicked it then finds a match from the worksheet named Data that matched the text from textbox 1 and adds the value from combobox 2 in to the worksheet. I have attached a little mock up and filled the values in so you only need to click the command button. I can not seem to get it to work, any help would be great.
Hope this make sense..
Code
- Private Sub CommandButton1_Click()
- Application.DisplayAlerts = False
- Dim m As Variant
- With ThisWorkBook.WorkSheets ("Data")
- m = Application.Match(Val(Me.TextBox1.Text), .Columns(1), 0)
- If Not IsError(m) Then
- With .Cells(CLng(m), "D")
- If ComboBox1.Value = "OUT" Then
- .Value = .Value + Val(ComboBox2.Value)
- Else
- With .Cells(CLng(m), "E")
- If ComboBox1.Value = "IN" Then
- .Value = .Value - Val(ComboBox2.Value)
- End If
- End With
- End If
- End With
- End If
- End With
- Application.DisplayAlerts = True
- End Sub