لا تستعمل Application.InputBox
افضل استعمال vba.InputBox
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub ListBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
Dim rng As Range, LR As Long
Dim x
x = InputBox("Please enter a Quntity")
If x = False Or StrPtr(x) = 0 Or Not IsNumeric(x) Then
Exit Sub
Else
LR = Sheets("invoice").Cells(Rows.Count, "E").End(xlUp).Row + 1
Set rng = Sheets("invoice").Cells(LR, 4)
If ListBox1.Value <> "" Then
rng.Value = ListBox1.Value
rng.Offset(0, 1).Value = ListBox1.List(ListBox1.ListIndex, 1)
rng.Offset(0, 4).Value = ListBox1.List(ListBox1.ListIndex, 2)
rng.Offset(0, 2).Value = x
End If
End If
End If
End Sub
Private Sub TextBox1_Change()
Dim LR As Integer, R As Integer, T As Integer
ListBox1.Clear
With Sheets("Codes")
LR = .Cells(.Rows.Count, 2).End(xlUp).Row
For R = 2 To LR
If .Cells(R, 2) Like "*" & TextBox1.Text & "*" Then
ListBox1.AddItem
ListBox1.List(T, 0) = .Cells(R, 1)
ListBox1.List(T, 1) = .Cells(R, 2)
ListBox1.List(T, 2) = .Cells(R, 4)
ListBox1.List(T, 3) = .Cells(R, 5)
T = T + 1
End If
Next
End With
End Sub
Private Sub UserForm_Activate()
TextBox1_Change
ListBox1.ListIndex = 0
End Sub