读取条形码后跳转到Excel单元格以查看是否存在匹配项 [英] Jumping to an excel cell after reading a barcode to see if there is a match

查看:188
本文介绍了读取条形码后跳转到Excel单元格以查看是否存在匹配项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张带有条形码和产品详细信息的Excel工作表.我想使用条形码扫描仪在excel工作表中查找与这些条形码关联的项目(出于库存目的)并标记它们.我希望excel跳到相应的单元格中.我已经尝试通过阅读类似的帖子来创建宏,而据我所知:

I have an excel sheet with barcodes and details of products. I would like to use a barcode scanner to find items associated with those barcodes in my excel sheet (for inventory purposes) and mark them. I would like excel to jump into the corresponding cell. I have tried creating a macro by reading similar posts and this is as far as I have got:

Private Sub CommandButton1_Click()

 Dim code As Variant
 Dim matchedCell As Range


    code = InputBox("Please scan a barcode and hit enter if you need to")
    Set matchedCell = Range("C2:C100").Find(what:=code, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=True)
    If Not matchedCell Is Nothing Then
    Range(matchedCell.Address).Interior.ColorIndex = 6
    Else: MsgBox "Barcode Not Found"
    End If

End Sub

这仅突出显示单元格.理想情况下,我想突出显示整个行.我也想跳到相应的单元格.我没有这方面的经验,我只是在网上找到了两个不同的示例,直到我使它可以正常工作而没有错误消息.如何修改它以添加其他功能?

This only highlights the cell. Ideally, I would like to highlight the whole row. I would also like to jump to the corresponding cell. I have no experience in this and I just pulled a couple of different examples that I found online until I got this to work without error message. How can I modify this to add additional functions?

在将条形码输入到输入框中时,我也遇到了问题.我所能做的就是通过扫描将其输入到单元格中,或者将数字手动输入到输入框中-如何使它将扫描的代码输入到此输入框中?光标在正确的位置,但是将被忽略.

I also have a problem with entering the barcode into the inputbox. All I can do is get it entered into a cell by scanning it or manually enter the number into the input box - how could I make it enter the scanned code into this inputbox? The cursor is in the right place, but that is ignored.

谢谢

推荐答案

Private Sub CommandButton1_Click()

    Dim code As Variant Dim matchedCell As Range

    code = InputBox("Please scan a barcode and hit enter if you need to")

    Set matchedCell = Range("C2:C100").Find(what:=code, LookIn:=xlValues, _
                      lookat:=xlWhole, MatchCase:=True)

    If Not matchedCell Is Nothing Then
        With matchedCell
            Application.Goto .Cells(1)
            .Resize(1, 10).Interior.ColorIndex = 6
        End With
    Else
        MsgBox "Barcode Not Found"
    End If

End Sub

这篇关于读取条形码后跳转到Excel单元格以查看是否存在匹配项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆