2021-04-29

Using an input box and msg box to search for data in excel VBA

I'm working on a sub that requires me to make it so that a user can search for their ProductID with an input box and then let them know with a msgbox whether it was or was not found, but I can't get the code right. What am I doing wrong here? Totally lost (code below):

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


from Recent Questions - Stack Overflow https://ift.tt/3e0NSfg
https://ift.tt/eA8V8J

No comments:

Post a Comment