Search manually from sub_Change

NDMDRB

Board Regular
Joined
Jun 20, 2016
Messages
164
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have a userform with a lot of textboxes, one of these textboxes is "txtBarCode" that allows me to enter any Barcode to check if the item is exist or not and lookup values for "txtItemName" & "txtPrice" and I have the code below that works very well
But, sometimes I need to enter the Barcode number manually
With my code below, If I entered "1" it will get the values of "B2" & "C2"
But if I need to search for the barcode "12" it will get the value of "B2" & "C2" and then "B3" & "C3" (Because the lookup values change with every change I made)

Is there any way to make this code works with 2 entry ways, Barcode Scanner & manually?

Code:
Private Sub txtBarCode_Change()
Dim ws As Worksheet
Set ws = Sheet2
On Error Resume Next
If WorksheetFunction.CountIf(Sheet1.Range("A:A"), Me.txtBarCode.Value) = 0 Then
MsgBox "This item is not exist"
Me.txtBarCode.Value = ""
Exit Sub
End If
With Me
.txtItemName = Application.WorksheetFunction.VLookup(CLng(Me.txtBarCode), Sheet1.Range("A4").CurrentRegion, 2, 0)
.txtPrice = Format(Application.WorksheetFunction.VLookup(CLng(Me.txtBarCode), Sheet1.Range("A4").CurrentRegion, 4, 0), "#,##0")
nr = ws.Cells(Rows.Count, "P").End(xlUp).Row + 1
ws.Cells(nr, "T") = Sheet2.Cells(Rows.Count, "T").End(xlUp).Value + 1
ws.Cells(nr, "U") = CDbl(Me.txtBarCode)
ws.Cells(nr, "V") = Application.WorksheetFunction.VLookup(CLng(Me.txtBarCode), Sheet1.Range("A4").CurrentRegion, 2, 0)
ws.Cells(nr, "W") = CDbl(Format(Application.WorksheetFunction.VLookup(CLng(Me.txtBarCode), Sheet1.Range("A4").CurrentRegion, 4, 0), "#,##0"))
txtBarCode = "" 'because this line of code I added below lines of code
Call txtAmount_Change
Me.txtBarCode.SetFocus
End With
End Sub


ABC
1BarcodeItem NamePrice
21Test1000
32Test22000
4123Test33000

<tbody>
</tbody>
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try using _AfterUpdate or _Exit instead of _Change
 
Upvote 0
If there is no solution for what I need then will use AfterUpdate

But I need to get the values directly because I may enter 100 items in one invoice, and it's easy and faster if the event is _Change

What I need is to use my form as cashier
 
Upvote 0

Forum statistics

Threads
1,214,392
Messages
6,119,254
Members
448,879
Latest member
oksanana

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