Find a match in a list

  • Thread starter Thread starter jlclyde
  • Start date Start date
J

jlclyde

When in coding for a macro I am not sure how to look at a value from
an input box (s1) and compare it to a list for possible matches.
(Range("A1:A10") I know how to get it there once this is done, but
for some reason this is kicking my butt.
Thanks for the help,
Jay
 
Jay

You can do this by setting a range variable, like so

Sub FindData()
Dim WhatToFind As String
Dim fnd As Range
WhatToFind = InputBox("EnterData")
Set fnd = Range("A1:A25").Find(WhatToFind)
If Not fnd Is Nothing Then
MsgBox "I found " & WhatToFind & " at " & fnd.Address
Else
MsgBox "I found nowt"
End If
End Sub

And then testing if it is not 'nothing' after 'setting' it

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
web: www.excelusergroup.org
web: www.nickhodge.co.uk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top