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 gt; quot;Helloquot;
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
Chris,
Try some code like the following:
Dim FoundCell As Range
Dim WhatToFind As String
WhatToFind = InputBox(quot;Find What?quot;)
If WhatToFind = quot;quot; Then
Exit Sub
End If
Set FoundCell = Range(quot;A1:A20quot;).Find(what:=WhatToFind, _
LookIn:=xlValues, lookat:=xlWhole)
If Not FoundCell Is Nothing Then
FoundCell.Select
MsgBox WhatToFind amp; quot; found at quot; amp; FoundCell.Address
End If--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.comquot;Chrisquot; gt; wrote in message
...
gt; Hello I am new to Excel VBA and think I have thrown myself into
gt; the deep end
gt; by trying to produce an advanced spreadsheet.
gt;
gt; What I am trying to do is have a button on my spreadsheet that
gt; when clicked
gt; opens up an Input Box, the user can input some data and then it
gt; searches a
gt; column for the matching input.
gt;
gt; For Example
gt;
gt; Input Box gt; quot;Helloquot;
gt;
gt; I would like it to then search column A1:A20 for the Word
gt; Hello. Once found
gt; just leave the cell selected and a message box saying the word
gt; has been found.
gt;
gt; If anyone could do this for me I would be very greatful I have
gt; tried now for
gt; 2 days and finding it really tough.
gt;
gt; Thanks for the help
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
quot;Chip Pearsonquot; wrote:
gt; Chris,
gt;
gt; Try some code like the following:
gt;
gt; Dim FoundCell As Range
gt; Dim WhatToFind As String
gt; WhatToFind = InputBox(quot;Find What?quot;)
gt; If WhatToFind = quot;quot; Then
gt; Exit Sub
gt; End If
gt; Set FoundCell = Range(quot;A1:A20quot;).Find(what:=WhatToFind, _
gt; LookIn:=xlValues, lookat:=xlWhole)
gt; If Not FoundCell Is Nothing Then
gt; FoundCell.Select
gt; MsgBox WhatToFind amp; quot; found at quot; amp; FoundCell.Address
gt; End If
gt;
gt;
gt; --
gt; Cordially,
gt; Chip Pearson
gt; Microsoft MVP - Excel
gt; Pearson Software Consulting, LLC
gt; www.cpearson.com
gt;
gt;
gt; quot;Chrisquot; gt; wrote in message
gt; ...
gt; gt; Hello I am new to Excel VBA and think I have thrown myself into
gt; gt; the deep end
gt; gt; by trying to produce an advanced spreadsheet.
gt; gt;
gt; gt; What I am trying to do is have a button on my spreadsheet that
gt; gt; when clicked
gt; gt; opens up an Input Box, the user can input some data and then it
gt; gt; searches a
gt; gt; column for the matching input.
gt; gt;
gt; gt; For Example
gt; gt;
gt; gt; Input Box gt; quot;Helloquot;
gt; gt;
gt; gt; I would like it to then search column A1:A20 for the Word
gt; gt; Hello. Once found
gt; gt; just leave the cell selected and a message box saying the word
gt; gt; has been found.
gt; gt;
gt; gt; If anyone could do this for me I would be very greatful I have
gt; gt; tried now for
gt; gt; 2 days and finding it really tough.
gt; gt;
gt; gt; Thanks for the help
gt;
gt;
gt;
- Apr 21 Sat 2007 20:36
Searching data in a column via Input Box
close
全站熱搜
留言列表
發表留言