vba Excel条码扫描宏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27108954/
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-12 05:20:32  来源:igfitidea点击:

Excel Barcode Scanning Macro

excelexcel-vbabarcode-scannervba

提问by HiFi

I deal with a large number of unique products (10,000+ per year on my own) and I am looking to optimise Excel to make my job more efficient. I have a USB barcode scanner and want to implement this into my process.

我处理大量独特的产品(我自己每年 10,000 多个),我希望优化 Excel 以提高我的工作效率。我有一个 USB 条码扫描仪,想在我的流程中实现它。

My suppliers send me a large spreadsheet with product info, such as barcode number and other product details. I also recieve samples of the product and need to register them within the system, and cross reference them with the spreadsheet.

我的供应商向我发送了一个包含产品信息的大型电子表格,例如条形码编号和其他产品详细信息。我还收到了产品样本,需要在系统中注册它们,并在电子表格中交叉引用它们。

I am looking for a macro which: when it recieves an input from the scanner, searches and navigates within the spreadsheet to the row where the product is, and if the same barcode has a second scan within 3-5 seconds, fills in the date in column x, and if column x is an occupied cell, fills in the date in column y.

我正在寻找一个宏:当它收到来自扫描仪的输入时,在电子表格中搜索并导航到产品所在的行,如果相同的条形码在 3-5 秒内进行了第二次扫描,则填写日期在 x 列中,如果 x 列是一个被占用的单元格,则在 y 列中填写日期。

This will allow me to both search for the product without filling in the date (not double scanning) for general lookups, but also to check the product in and out with the date.

这将使我既可以在不填写日期(不是双重扫描)的情况下搜索产品以进行一般查找,也可以使用日期检查产品。

Thank you so much in advance for your help!

非常感谢您的帮助!

回答by paul

If it helps, the fact that this question relates to barcode scanning could be disregarded - barcode scanners are implemented simply as keyboard devices that 'type' the number scanned (some append 'enter' on the end, some don't, and some are configurable).

如果有帮助,则可以忽略此问题与条码扫描相关的事实 - 条码扫描器只是作为键盘设备实现,用于“键入”扫描的数字(有些在末尾附加“输入”,有些不附加,有些则是可配置)。

So the answer to your question need not be in any way specific to the scanning of barcodes. It pretty much just needs an InputBoxthat takes a number and then uses that number in the MATCHfunction.

因此,您的问题的答案不必以任何方式特定于条码扫描。它几乎只需要一个InputBox接受一个数字然后在MATCH函数中使用该数字的函数。

e.g.

例如

code = InputBox("Please scan a barcode and hit enter if you need to")
matchedCell = match(code, productRange, 0)
matchedCell.Offset(0,2) = Now

where productRangeis the range of cells that your product listing takes up.

productRange您的产品列表占用的单元格范围在哪里。

edit:

编辑:

To start with, follow a tutorial like this one: http://www.excel-easy.com/vba/create-a-macro.html

首先,请按照以下教程进行操作:http: //www.excel-easy.com/vba/create-a-macro.html

You should end up with a button on your form that, when clicked, will put the word "hello" in cell A1.

您应该最终在表单上有一个按钮,单击该按钮后,会将单词“hello”放入单元格 A1 中。

Once you have this working, replace the 'hello' code with the lines I suggested above and you should be well on your way.

完成此操作后,将“hello”代码替换为我上面建议的行,您应该会顺利进行。