Link to home
Start Free TrialLog in
Avatar of bhagatali
bhagataliFlag for United States of America

asked on

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.
Avatar of SiddharthRout
SiddharthRout
Flag of India image

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
Avatar of smartchaps
smartchaps

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

=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

Open in new window

Salary-Calculator.xls
Avatar of Rob Henson
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
Avatar of bhagatali

ASKER

Thanks for your inputs. I am attaching a sample file which shows what we intend to achieve.

Regards
Ali. Sample.xlsx
ASKER CERTIFIED SOLUTION
Avatar of SiddharthRout
SiddharthRout
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial