Hello
I got this code by Dante Amore
the code will subtract from column D in sheet and sum to column D in sheet after matching ID in textbox1 with column C based on selected optionbutton
now I want when click commandbutton1 then will show message box and show the available QTY in title message box based inside sheet for column D and show me inside message box how QTY become inside the sheet for column D after sum or subtract inside sheet , but if I write QTY in textbox2 for the ID in textbox1 and bigger than available QTY inside sheet then should show the message by warning and show me available QTY in title message box and show me how remaining QTY after subtract based on optionbutton2,4 and exit sub without subtract from sheet .
I got this code by Dante Amore
the code will subtract from column D in sheet and sum to column D in sheet after matching ID in textbox1 with column C based on selected optionbutton
now I want when click commandbutton1 then will show message box and show the available QTY in title message box based inside sheet for column D and show me inside message box how QTY become inside the sheet for column D after sum or subtract inside sheet , but if I write QTY in textbox2 for the ID in textbox1 and bigger than available QTY inside sheet then should show the message by warning and show me available QTY in title message box and show me how remaining QTY after subtract based on optionbutton2,4 and exit sub without subtract from sheet .
QQ.xlsx | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | ITEM | DATE | ID | QTY | ||
2 | 1 | 45102 | SDFR-1000 | 20 | ||
3 | 2 | 45103 | SDFR-1001 | 20 | ||
4 | 3 | 45072 | SDFR-1002 | 200 | ||
5 | 4 | 45073 | SDFR-1003 | 201 | ||
ASDD |
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