Private Sub AddNew_Bundle_Txtbox_Change()
If AddNew_Cost_Txtbox.Value = "" Then AddNew_Cost_Txtbox.Value = 1
If AddNew_Bundle_Txtbox.Value = "" Then AddNew_Bundle_Txtbox.Value = 1
AddNew_Piece_Txtbox.Value = (AddNew_Cost_Txtbox.Value / AddNew_Bundle_Txtbox.Value)
End Sub
Private Sub AddNew_Button_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Inventory")
Dim lr As Long
lr = Sheets("Inventory").Range("B" & Rows.Count).End(xlUp).Row
'' Validation ''
If Me.AddNew_Item_Txtbox.Value = "" Then
MsgBox "Please Enter Item Name", vbCritical
Exit Sub
End If
If Me.AddNew_Used_Txtbox.Value = "" Then
MsgBox "Please Enter Used For", vbCritical
Exit Sub
End If
If IsNumeric(Me.AddNew_Cost_Txtbox.Value) = False Then
MsgBox "Please Enter the correct Cost", vbCritical
Exit Sub
End If
If IsNumeric(Me.AddNew_Bundle_Txtbox.Value) = False Then
MsgBox "Please Enter the correct Bundle", vbCritical
Exit Sub
End If
If IsNumeric(Me.AddNew_Piece_Txtbox.Value) = False Then
MsgBox "Please Enter the correct Price per Piece", vbCritical
Exit Sub
End If
If Me.AddNew_Remarks_Txtbox.Value = "" Then
MsgBox "Please Enter Remarks", vbCritical
Exit Sub
End If
'' Adding data in the excel sheet ''
With sh
ActiveWorkbook.Sheets("Inventory").Protect Password:="Roshier", userinterfaceonly:=True
.Cells(lr + 1, "B").Value = Me.AddNew_Item_Txtbox.Value
.Cells(lr + 1, "C").Value = Me.AddNew_Used_Txtbox.Value
.Cells(lr + 1, "D").Value = Me.AddNew_Cost_Txtbox.Value
.Cells(lr + 1, "E").Value = Me.AddNew_Bundle_Txtbox.Value
.Cells(lr + 1, "F").Value = Me.AddNew_Piece_Txtbox.Value
.Cells(lr + 1, "H").Value = Me.AddNew_Remarks_Txtbox.Value
End With
'' Clear Data ''
Me.AddNew_Item_Txtbox.Value = ""
Me.AddNew_Used_Txtbox.Value = ""
Me.AddNew_Cost_Txtbox.Value = ""
Me.AddNew_Bundle_Txtbox.Value = ""
Me.AddNew_Piece_Txtbox.Value = ""
Me.AddNew_Remarks_Txtbox.Value = ""
MsgBox "Data has been added!", vbInformation
AddNew_Item_Txtbox.SetFocus
End Sub
Private Sub AddNew_Cost_Txtbox_Change()
If AddNew_Cost_Txtbox.Value = "" Then AddNew_Cost_Txtbox.Value = 1
If AddNew_Bundle_Txtbox.Value = "" Then AddNew_Bundle_Txtbox.Value = 1
AddNew_Piece_Txtbox.Value = (AddNew_Cost_Txtbox.Value / AddNew_Bundle_Txtbox.Value)
End Sub
Private Sub AddNew_Cancel_Click()
Unload AddNew_Item
End Sub
Private Sub AddNew_Cost_Txtbox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If (KeyAscii > 47 And KeyAscii < 58) Then
KeyAscii = KeyAscii
Else
KeyAscii = 0
End If
End Sub
Private Sub AddNew_Bundle_Txtbox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If (KeyAscii > 47 And KeyAscii < 58) Then
KeyAscii = KeyAscii
Else
KeyAscii = 0
End If
End Sub