【发布时间】:2021-07-22 08:11:21
【问题描述】:
我正在开发一个要求我制作的 sub,以便用户可以使用输入框搜索他们的 ProductID,然后使用 msgbox 让他们知道是否找到了它,但我不能获取正确的代码。我在这里做错了什么?完全丢失(代码如下):
Sub test()
Dim Worksheet As Range
Dim ProductID As Variant
ProductID = InputBox("Please enter the Product ID")
With Worksheets(1).Range("A1:Z1000")
Set ProductID = .Find("ProductID", LookIn:=xlWhole)
If found Then
MsgBox ProductID("was Found")
Else
MsgBox ProductID & (" was NOT Found")
End If
End With
End Sub
【问题讨论】:
-
Dim found As Range,Set found = .Find(ProductID, LookIn:=xlWhole),If Not found Is Nothing Then,MsgBox ProductId & "was Found",Else,MsgBox ProductID & " was NOT Found" -
大本,非常感谢!当我尝试这个时,它会显示“无效或不合格的参考”并突出显示 .Find。
-
Sub test() Dim found As Range Set found = .Find(ProductID, LookIn:=xlWhole) If Not found Is Nothing Then MsgBox ProductID & "was Found" Else MsgBox ProductID & " was NOT Found " 结束子
-
你需要
With Worksheets(1).Range("A1:Z1000"),然后是End If和End With。 -
如果我想引用整个工作表而不是 A1:Z1000,我该怎么做?
标签: excel vba search inputbox msgbox