#1   Report Post  
Dallas Green
 
Posts: n/a
Default Searching Macro

Does anyone know how to create a macro that will automatically search another
worksheet for a name and then enter in a third item once it finds the name.

For example: Search entire worksheet 1 for "John" then enter in the date
that John's name is under?

Is this possible? HELP PLEASE!!!
  #2   Report Post  
David McRitchie
 
Posts: n/a
Default

Are you actually saying that "John" could appear in ANY cell and if
you get a hit you want the value of the cell above that cell. Or is
only one column to be searched.
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Dallas Green" wrote in message ...
Does anyone know how to create a macro that will automatically search another
worksheet for a name and then enter in a third item once it finds the name.

For example: Search entire worksheet 1 for "John" then enter in the date
that John's name is under?

Is this possible? HELP PLEASE!!!



  #3   Report Post  
Dallas Green
 
Posts: n/a
Default

I am actually saying that "John" could appear in ANY cell and if I get a hit
I want the value of the cell above "John". So is it possible? Thanks.

"David McRitchie" wrote:

Are you actually saying that "John" could appear in ANY cell and if
you get a hit you want the value of the cell above that cell. Or is
only one column to be searched.
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Dallas Green" wrote in message ...
Does anyone know how to create a macro that will automatically search another
worksheet for a name and then enter in a third item once it finds the name.

For example: Search entire worksheet 1 for "John" then enter in the date
that John's name is under?

Is this possible? HELP PLEASE!!!




  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

It's possible, but you didn't give many details.

This may get you started...

I assumed that you wanted to look for John on Sheet1. Case didn't matter. It
was in a cell by itself. You wanted to find the first occurrence. And you
wanted to copy the cell above that "john" cell in A1 of Sheet2.



Option Explicit
Sub testme()

Dim FoundCell As Range
Dim wks As Worksheet
Dim WhatToLookFor As String
Dim destCell As Range

Set wks = Worksheets("Sheet1")
WhatToLookFor = "John"

Set destCell = Worksheets("sheet2").Range("a1")

With wks
Set FoundCell = .Cells.Find(what:=WhatToLookFor, _
after:=.Cells(.Cells.Count), LookIn:=xlValues, _
lookat:=xlWhole, searchorder:=xlNext, _
MatchCase:=False)

If FoundCell Is Nothing Then
MsgBox WhatToLookFor & " wasn't found on: " & wks.Name
Else
If FoundCell.Row = 1 Then
MsgBox WhatToLookFor & " was found in Row 1--nothing above!"
Else
'.offset(-1,0) is one row up in the same column
FoundCell.Offset(-1, 0).Copy _
Destination:=destCell
End If
End If
End With
End Sub

Dallas Green wrote:

I am actually saying that "John" could appear in ANY cell and if I get a hit
I want the value of the cell above "John". So is it possible? Thanks.

"David McRitchie" wrote:

Are you actually saying that "John" could appear in ANY cell and if
you get a hit you want the value of the cell above that cell. Or is
only one column to be searched.
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Dallas Green" wrote in message ...
Does anyone know how to create a macro that will automatically search another
worksheet for a name and then enter in a third item once it finds the name.

For example: Search entire worksheet 1 for "John" then enter in the date
that John's name is under?

Is this possible? HELP PLEASE!!!





--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro and sub rountines The Good Deeds Team Excel Discussion (Misc queries) 1 March 23rd 05 11:26 PM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM
Macro Formula revision? Mark Excel Worksheet Functions 1 November 28th 04 01:43 AM


All times are GMT +1. The time now is 11:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"