Excel条形码扫描器列数据行

我正在使用条形码扫描器来做大量的库存,我想把数据input到excel中。 我可以在每次扫描后改变扫描仪的行为方式,例如制表符,返回等。但是我的大问题是,为了有效地提供数量,我必须扫描项目代码(7位数),然后扫描数量从0到9连续。 这样548真的是5,4,8,当使用excel时,它将每个数字放到一个新的单元格中。 我想做什么,但没有VBA印章这样做是有excel检查,看是否长度是7位数字或一位数字。 对于每一个数字号码,它应该将数字移动到与前面的7位数字相同的行中的下一个单元格,以便每个连续的一个数字号码被组合,就像excel连接单元格一样。 那么它应该删除原始列中的单个数字,并使下一行以7位数的条形码号码开始。

我希望这是有道理的。

例:

7777777 3 4 5 7777778 4 5 6 7777779 7 8 9 

应该成为:

 | 7777777 | 345 | | 7777778 | 456 | | 7777779 | 789 | 

谢谢!!

我这样设置我的工作表:

在这里输入图像说明

然后运行下面的代码

 Sub Digits() Application.ScreenUpdating = False Dim i&, r As Range, j& With Columns("B:B") .ClearContents .NumberFormat = "@" End With For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row Set r = Cells(i, 1) If Len(r) = 7 Then j = 1 Do Until ((Len(r.Offset(j, 0).Text) = 7) Or (IsEmpty(r.Offset(j, 0)))) Cells(i, 2) = CStr(Cells(i, 2).Value) & CStr(r.Offset(j, 0)) j = j + 1 Loop End If Set r = Nothing Next For i = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1 If Len(Cells(i, 1)) < 7 Then Rows(i & ":" & i).Delete Next i Columns.AutoFit Application.ScreenUpdating = True End Sub 

和我得到的结果:

在这里输入图像说明

这就是我开始做的,但我认为你的新解决scheme会更好。 多谢你!

 Sub Digits() Application.ScreenUpdating = False Dim i, arr, r As Range Dim a, b, c, d, e Dim y For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row Set r = Cells(i, 1) Set a = Cells(i + 1, 1) Set b = Cells(i + 2, 1) Set c = Cells(i + 3, 1) Set d = Cells(i + 4, 1) Set e = Cells(i + 5, 1) If Len(a) = 7 Then y = 0 ElseIf Len(b) = 7 Then y = 1 ElseIf Len(c) = 7 Then y = 2 ElseIf Len(d) = 7 Then y = 3 ElseIf Len(e) = 7 Then y = 4 Else: y = 0 End If If Len(r) = 7 Then arr = Range("A" & i & ":A" & i + y).Value Range("B" & i & ":F" & i) = WorksheetFunction.Transpose(arr) End If Next Cells.Replace "#N/A", "", xlWhole Application.ScreenUpdating = True End Sub