sum or subtract based on optuinbutton number on userform to column inside sheet

Maklil

Board Regular
Joined
Jun 23, 2022
Messages
146
Office Version
  1. 2019
Platform
  1. Windows
Hello
I want adding or subtract when the values writing in textbox2 to column D based on matching ID in textbox1 with column C inside the sheet

original data in the sheet



ASDD.xlsm
ABCD
1ITEMDATEIDQTY
2125/06/2023SDFR-100020.00
3226/06/2023SDFR-100120.00
4326/05/2023SDFR-1002200.00
5427/05/2023SDFR-1003201.00
SH


if select optionbutton 1IMPORT then will sum to column C after matching ID as marked the cell
S1.JPG



and when select option button 2 (EXPORTR) then will subtract from column C for the ID (picture 2 depends on picture1 )
S2.JPG


and if select optionbutton3(RE) then will sum to column C for the ID (picture 3 depends on pictur2 )
S3.JPG


and if select optionbutton 4(ER) then will subtract from column C for the ID (picture 4 depends on picture31 )

S4.JPG
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try this:

VBA Code:
Private Sub CommandButton1_Click()
  Dim f As Range
  
  'Validations
  With TextBox1
    If .Value = "" Then
      MsgBox "Enter ID"
      .SetFocus
      Exit Sub
    End If
    Set f = Range("C:C").Find(.Value, , xlValues, xlWhole, , , False)
    If f Is Nothing Then
      MsgBox "ID does not exists"
      .SetFocus
      Exit Sub
    End If
  End With
  With TextBox2
    If .Value = "" Or Not IsNumeric(.Value) Then
      MsgBox "Enter QTY"
      .SetFocus
      Exit Sub
    End If
  End With
  
  'Sum or subtract
  With f.Offset(, 1)
    Select Case True
      Case OptionButton1 Or OptionButton3
        .Value = .Value + Val(TextBox2.Value)
      Case OptionButton2 Or OptionButton4
        .Value = .Value - Val(TextBox2.Value)
      Case Else
        MsgBox "No option was selected"
    End Select
  End With
End Sub


It is recommended, instead of textbox1, you should put a combobox to select the ID instead of capturing the entire ID.
;)
 
Upvote 0
Solution
It is recommended, instead of textbox1, you should put a combobox to select the ID instead of capturing the entire ID.
without any doubt , that's correct I will change it .;)
thank you for your assistance.:)
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,308
Members
449,152
Latest member
PressEscape

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top