我正在尝试扫描条形码,并让Excel移动到正确的单元格

当我扫描一个条形码时,我需要将光标移动到Excel中的右侧单元格,但是现在它停止了。 我不想在Excel选项中进行更改,因为我需要在单击其他工作表上的input时使单元格光标向下。

我find的一个解决scheme是我最初开始使用的代码块。

在插入的情况下从开发人员打开一个ActiveX文本框,并将其放置在您希望扫描的工作表中。 selectA1,然后点击文本框。 确保devise模式视图在开发者closures(看工具栏function区)。

**附近的行是你需要改变的。 这是设定的长度,但你也可以玩其他事情,如案例。 尝试使用12345作为值的条形码。

 Private Sub TextBox1_Change() **If Len(TextBox1.Value) = 5 Then** ActiveCell.Value = TextBox1.Value ActiveCell.Offset(1).Activate Application.EnableEvents = False TextBox1.Activate TextBox1.Value = "" End If End Sub 

案例。 尝试使用“Waste R-1”作为条形码。

 Private Sub TextBox1_Change() Dim ws As Worksheet, v, k, i, j Set ws = Worksheets("Sheet1") v = TextBox1.Value k = 0 i = 0 j = 0 Select Case v Case "Waste R - 1": i = 2 k = 1 j = "Waste R - 1" 'Start i at whatever column you want to start at 'k is the type of case and if statement you want to run (I have several, but for simplicity, I have only attached one) End Select If k = 1 Then ws.Cells(1, 1) = ws.Cells(1, 1).Value + 1 ' adds number into cell (A1) to reference which column to be in ' Starts in Column A then adds a value of one to reference column B i = ws.Cells(1, 1) 'Sets i = to the A1 value Cells(1, i).Value = j ' You may be able to set this to textbox1.value ' Says to put the Textbox Value into whatever column and row A TextBox1.Activate TextBox1.Value = "" End If End Sub 

确保在单元格A1中input值2以启动。

如果你想最终你可以把它变成一个循环。 我相信有更简单的方法,但我做了一个Excel模板粘贴到VBA工作表一个模块的参考。 更新非常简单。 让我知道如果我可以帮助任何其他条码问题