How to check for a value in different tabs in excel?

Hi,

I have an excel sheet which has around 25 tabs. There is a master sheet which has names of all employees in our system. I have to use the employee name from this master sheet and search for occurrence of this name in any of the other sheets. If any occurrence is found, I need to have the sum of salary in those excel tabs corresponding to the employee name displayed in my master sheet.

For example, I have Employee Name John in my master sheet. If John appears in sheet 5, 6 and 10. I need to find the value of salary in those 3 excel tabs corresponding to John and then display in my main tab the sum of all salary for John.

Thanks for any help.

Regards
Ali.
Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
A sample file is definitely required as you have bot mentioned which column has the salary. If you can upload a sample file then I can give you the code.

Sid
Commented:
As you said will these tabs sheets) 5, 6 and 10 contain salary for only John or other employees also. Can you attach these sheets including Master sheet so that exact format of data in those sheets is known and solution is provided.
Commented:
Tried and Tested.

Sample Attached. Please amend as applicable. I have created a Userdefined Function so that all you need to do is use this formula in the cell

=CalcSal(A2)

Where A2 contains "John"

Sid

Code Used

``````Option Explicit

Public Function CalcSal(strEmployee As String) As Double
Dim TotSal As Double
Dim ws As Worksheet
Dim acell As Range

On Error GoTo whoa

Application.ScreenUpdating = False

For Each ws In ActiveWorkbook.Sheets
If ws.Name <> ActiveSheet.Name Then
'~~> Column where the name is. Ex: If the name is in Col A then 1
Set acell = ws.Columns(1).Find(What:=strEmployee, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

If Not acell Is Nothing Then
'~~> If the salary is in Col B then offset 1 of Col A
'~~> If the salary is in Col C then offset 2 of Col A and so on
TotSal = TotSal + acell.Offset(, 1).Value
End If
End If
Next ws

CalcSal = TotSal

letsContinue:
Application.ScreenUpdating = True
Exit Function
whoa:
MsgBox Err.Description
Resume letsContinue
End Function
``````
Salary-Calculator.xls
Finance AnalystCommented:
You could use a pivot table with multiple data sources but I don't have much experience of this  other than knowing it is possible.

Cheers
Rob H
Author Commented:
Thanks for your inputs. I am attaching a sample file which shows what we intend to achieve.

Regards
Ali. Sample.xlsx
Commented:
Here I have updated the code and pasted the formula. Check the Yellow Cells.

Sid
Salary-Example.xls

Experts Exchange Solution brought to you by