VBA Excel 代码条码扫描

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16112548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 20:44:28  来源:igfitidea点击:

VBA Excel Code Barcode Scanning

excelexcel-vbaexcel-2010vba

提问by user2270747

I have this excel spreadsheet and I'm using a barcode scanner, every time I capture something with the barcode scanner the cursor skip one column.

我有这个 excel 电子表格,我正在使用条形码扫描仪,每次我用条形码扫描仪捕获某些东西时,光标都会跳过一列。

enter image description here

在此处输入图片说明

For example at A3 cell the info is capture so the cursor will move to C3, at C3 I capture another barcode and the cursor will move to E3 and so on; once is at G3, should go back to A4 to capture another box.

例如,在 A3 单元格中,信息被捕获,因此光标将移动到 C3,在 C3,我捕获另一个条形码,光标将移动到 E3,依此类推;一旦在 G3,应该返回 A4 以捕获另一个框。

This is the code that I have.....

这是我拥有的代码......

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Whoa

Application.EnableEvents = False
If Not Target.Cells.CountLarge > 1 Then
    If Not Intersect(Target, Columns(1)) Is Nothing Then
        Target.Offset(, 1).Select
    ElseIf Not Intersect(Target, Columns(2)) Is Nothing Then
        Target.Offset(, 1).Select
    ElseIf Not Intersect(Target, Columns(3)) Is Nothing Then
        Target.Offset(, 1).Select
    ElseIf Not Intersect(Target, Columns(4)) Is Nothing Then
        Target.Offset(, 1).Select
    ElseIf Not Intersect(Target, Columns(5)) Is Nothing Then
        Target.Offset(, 1).Select
    ElseIf Not Intersect(Target, Columns(6)) Is Nothing Then
        Target.Offset(, 1).Select
    ElseIf Not Intersect(Target, Columns(7)) Is Nothing Then
        Target.Offset(1, -6).Select
    End If
End If
Letscontinue:
    Application.EnableEvents = True
    Exit Sub
Whoa:
    MsgBox Err.Description
    Resume Letscontinue
End Sub

It works when I do it manually (without the scanner) but using the barcode scanner it returns to column B.

当我手动执行(没有扫描仪)但使用条形码扫描仪时它会返回到 B 列。

For example at G3 I capture the date with a barcode and then it moves to B4 and not to A4 so I can start scanning the second box.

例如,在 G3 我用条形码捕获日期,然后它移动到 B4 而不是 A4,所以我可以开始扫描第二个盒子。

I need some help to develop the right code so I can use my scanner to capture the inventory at my small warehouse

我需要一些帮助来开发正确的代码,以便我可以使用我的扫描仪在我的小仓库中捕获库存

回答by ExcelVbaIsFun

Perhaps your barcode scanner auto-inserts a tab or enter keystroke after each entry. Maybe your last line shoud be Target.Offset(1, -7).Select this -7 columns instead of six could compensate for the barcode scanner tabbing to the right an extra time. Or use

也许您的条码扫描器会在每次输入后自动插入一个选项卡或输入按键。也许你的最后一行应该是。选择Target.Offset(1, -7)这 -7 列而不是 6 列可以补偿条形码扫描仪向右移动的额外时间。或使用

cells(Target.row+1,1).Select

for the troublesome last line of code, this tells it to select the current row plus one, and definitively the column A or 1.

对于麻烦的最后一行代码,这告诉它选择当前行加一,并最终选择 A 或 1 列。