首页 > 解决方案 > 如何使用输入值来定位包含相同值的单元格?

问题描述

我有一个将数据存储在不同工作表中的 ERP 系统,现在我想创建一个宏,要求您输入 ID 号,并使用该输入找到输入值与 ID 号匹配的行。包含所有数据的存档已经为每一行生成了一个 ID 号。

我不知道如何解决这个问题,因为我对 VBA 和编程很陌生(到目前为止 3 天)

编辑:我可能还需要为 inputValue 添加一个 If 语句,该语句与列表中的任何 ID 号都不匹配

Sub PullBackUp()
    inputvalue = Application.InputBox("Type ID number", "Pull a delivery-note back up", Type:=1)

    If inputvalue = vbNullString Then
        MsgBox "Please type an ID number to proceed"
    Else  
        'Locate the row with the ID number from the inputValue
    End If
End Sub

我希望使用我获得的 ID 号来获取已放入数据的整行inputValue

标签: excelvba

解决方案


想象一下您的专栏是B

Range("B1").End(xlDown).Find(What:=inputValue, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False, SearchFormat:=False).Activate

供您参考:我转到“开发人员”菜单项,并在执行搜索时录制了一个宏列B


推荐阅读