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


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.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

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.

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.
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


Where A2 contains "John"


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

    Application.ScreenUpdating = True
    Exit Function
    MsgBox Err.Description
    Resume letsContinue
End Function

Open in new window

Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Rob HensonFinance 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.

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

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.