Creating a search function

Luke Emmett

New Member
Joined
Mar 6, 2018
Messages
1
Hi,

So i have a rule running which searches my database and highlights information depending on what data i entered in the search cell, thats all sorted what im trying to do now is create a promt which comes up for you to enter the thing your searching for in turn this promt enters the data into a cell to be searched for but when ive done the Macro evertime i click off the cell it deletes the data in the cell thus clearing the search.

What i want it do is leave the data in that cell so i can look through the database but then if i click the Search button again it clears that cell to begin a new search ive tried adding a 'If IsEmpty' but i want it to skip the string if it there is no data in there but if there is clear it and prepare for a new search?


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim numCell As Range


If IsEmpty(Range("G9").Value) = False Then
Range("G9").Clear
ElseIf IsEmpty(Range("G9").Value) = True Then GoTo SkipToHere
End If


SkipToHere:
If Target.Value = "SEARCH" Then
Set numCell = Target.Offset(0, 1)
numCell.Select
strPrompt = "Search"


On Error Resume Next
Num = InputBox(strPrompt, "Search", 0)
numCell.Value = numCell.Value + Num

End If
End Sub


Thanks in advance
Luke
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top