A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Links and Linking
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Create a search feature in a worksheet



 
 
Thread Tools Display Modes
  #1  
Old March 2nd, 2008, 02:41 PM posted to microsoft.public.excel.links
Wildfire7
external usenet poster
 
Posts: 1
Default Create a search feature in a worksheet


Hey all
This is my first post on this lovely forum i am hoping i cold get some
help because i need it urgently, i have searched around incase third
thread has already been posted but it has not so please help.

Is it possible to create a box in Sheet1 of an Excel workbook that when
you type in a word or phrase will search Sheet2 -- working just like the
"find" option on the toolbar?

My goal is to be able to put the word (for example) "depreciation" in a
cell on sheet 1 and have it look through sheet 2 and return the general
ledger accounts that have the word depreciation in them. (i.e.
"depreciation exp. computers", "depreciation exp.leased equipment").
The entries on sheet 2 have account numbers in the same cell as the
description. This would mimic the " find" feature, but wouldn't take me
away from the page I am working on.
I was trying to avoid making multiple lists and drop down menus as
there are hundreds of accounts.

Thankyou ever so much




--
Wildfire7
  #2  
Old March 4th, 2008, 01:08 AM posted to microsoft.public.excel.links
Gary''s Student
external usenet poster
 
Posts: 7,584
Default Create a search feature in a worksheet

We will use cell A1 on Sheet1 as the data to find. Enter something in A1 and
each cell in Sheet2 will be scanned. For each match, the address of the
match will be placed in column A and the match data will be placed in column
B. This is a worksheet event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set a = Range("A1")
Set w = Sheets("Sheet1")
If Intersect(t, a) Is Nothing Then Exit Sub
Application.EnableEvents = False
v = a.Value
Sheets("Sheet2").Activate
i = 2
For Each r In ActiveSheet.UsedRange
If InStr(r.Value, v) 0 Then
w.Cells(i, 1).Value = r.Address
w.Cells(i, 2).Value = r.Value
i = i + 1
End If
Next
Application.EnableEvents = True
Sheets("Sheet1").Activate
End Sub


Because it is worksheet code, it is very easy to install and automatic to use:

1. right-click the tab name near the bottom of the Excel window (Sheet1)
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you have any concerns, first try it on a trial worksheet.

If you save the workbook, the macro will be saved with it.


To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm





--
Gary''s Student - gsnu2007e


"Wildfire7" wrote:


Hey all
This is my first post on this lovely forum i am hoping i cold get some
help because i need it urgently, i have searched around incase third
thread has already been posted but it has not so please help.

Is it possible to create a box in Sheet1 of an Excel workbook that when
you type in a word or phrase will search Sheet2 -- working just like the
"find" option on the toolbar?

My goal is to be able to put the word (for example) "depreciation" in a
cell on sheet 1 and have it look through sheet 2 and return the general
ledger accounts that have the word depreciation in them. (i.e.
"depreciation exp. computers", "depreciation exp.leased equipment").
The entries on sheet 2 have account numbers in the same cell as the
description. This would mimic the " find" feature, but wouldn't take me
away from the page I am working on.
I was trying to avoid making multiple lists and drop down menus as
there are hundreds of accounts.

Thankyou ever so much




--
Wildfire7

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:47 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.