![]() |
Searching data in a column via Input Box
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 |
Searching data in a column via Input Box
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 "Chris" wrote in message ... 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 |
Searching data in a column via Input Box
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 "Chip Pearson" wrote: 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 "Chris" wrote in message ... 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 |
All times are GMT +1. The time now is 09:49 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com