Searching and calculating more than 1 record

newtoexcel123

Board Regular
Joined
Jul 4, 2008
Messages
116
I'm trying to create a small macro to search for records and add up the total number of hours each spend. I've hard code the search criteria. For instance, I want the marco to count the number of record(s) that are associated with Alan, and number of record(s) that are associated with Steven etc....

This is how the data in excel workbook looks like:

Name Hour Work Hour Rest
Alan 3 1
Alan 5 0.5
Steven 2 0
Alan 3 1.5
Ricky 5 0.5
Steven 3 0

I want the output to be like this:

Name Hour Work Hour Rest
Alan 11 3
Steven 5 0
Ricky 5 0.5

This is the search
Private Sub SearchRecord()
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

Using the above code, I could find 1 record only. How to code in such a way that I'm able to find all the record(s) associated with the search criteria.

Thank you.

Yours sincerely,
Johnson
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi, thank you for your message. The reason why I use marco is because this is a repetition tasks, and there are hundred of files. Therefore, I'm thinking of writing a marco to do this task.
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,544
Members
449,316
Latest member
sravya

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