Searching data in a column via Input Box

G

Guest

Hello I am new to Excel VBA and think I have thrown myself into the deep end
by trying to produce an advanced spreadsheet.

What I am trying to do is have a button on my spreadsheet that when clicked
opens up an Input Box, the user can input some data and then it searches a
column for the matching input.

For Example

Input Box > "Hello"

I would like it to then search column A1:A20 for the Word Hello. Once found
just leave the cell selected and a message box saying the word has been found.

If anyone could do this for me I would be very greatful I have tried now for
2 days and finding it really tough.

Thanks for the help
 
C

Chip Pearson

Chris,

Try some code like the following:

Dim FoundCell As Range
Dim WhatToFind As String
WhatToFind = InputBox("Find What?")
If WhatToFind = "" Then
Exit Sub
End If
Set FoundCell = Range("A1:A20").Find(what:=WhatToFind, _
LookIn:=xlValues, lookat:=xlWhole)
If Not FoundCell Is Nothing Then
FoundCell.Select
MsgBox WhatToFind & " found at " & FoundCell.Address
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
G

Guest

Thanks Chip however I found a solution and modified it to what I wanted its
pretty cool. Seperated into two different modules. Thanks for your time and
the reply.

Chris
 

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

Top