Search more than 1 records

newtoexcel123

Board Regular
Joined
Jul 4, 2008
Messages
116
I trying to create a small macro to look up some values that I've hard coded. For instance, I want to find the number of record(s) that are associated with Alan, and the number of record(s) that are associated with Steven. After which I want to calculate the total number of hours they spend individually.

In excel worksheet
Cell A
Name Hours
Alan 10
Alan 2
Steven 5
Robert 7





Private Sub Search()
Sheets("Sheet1").Select
Sheets("Sheet1").Range("A1:D22").Select

Set FoundText = Selection.Find(What:="Alan", After:=ActiveCell, LookIn _
:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)

If Not FoundText Is Nothing Then
FoundText.Select
FoundCellRow = ActiveCell.Row
Else
End If

Set FoundText = Selection.Find(What:="Steven", After:=ActiveCell, LookIn _:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)

If Not FoundText Is Nothing Then
FoundText.Select
FoundCellRow = ActiveCell.Row
Else
End If



End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

newtoexcel123

Board Regular
Joined
Jul 4, 2008
Messages
116
Hi, thank you for your message. I want to write marco because this is a repetition task, and there are hundred of files. Therefore, I'm wondering whether marco could do the job.
 
Upvote 0

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,348
You want to return values.

Excel's native functions are much better for that than any VB routine.
 
Upvote 0

Forum statistics

Threads
1,191,687
Messages
5,988,024
Members
440,125
Latest member
vincentchu2369

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
Top