Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8172857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:55:00+00:00 2026-06-06T21:55:00+00:00

Possible Duplicate: Excel macro to match and lineup rows I have an Excel workbook

  • 0

Possible Duplicate:
Excel macro to match and lineup rows

I have an Excel workbook with 2 Sheets with same set of columns but data arranged in different way. I need to compare Sheet 2 against Sheet 1 with the use of one or more Key column and identify unmatched records.

Data in sheet1:

UserId Name Salary DeptId DeptName Location
1      Loga 2000   1      HR       Chennai
2      Mano 1500   2      PM       Mumbai
3      Raj  2500   5      GM       Delhi

Data in sheet1:

UserId Name Salary DeptId DeptName Location
2      Mano 1500   2      PM       Mumbai
3      Raj  2500   5      GM       Delhi

first I need to match records based on UserId and DeptId, if matches in both the sheet Compare Salary -> if salary matches store the record with UserId as Salary Matched.
Similarly if UserId and DeptId matches in both the sheet then compare location -> if matches then store record with userid as location matched if not report as particular UserID not matched.,

I am planning to use HLookUp in VBA Macro for comparing but seems lengthy process when no.of rows increases and reduces performance as well.
is there any suggestion available ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:55:03+00:00Added an answer on June 6, 2026 at 9:55 pm

    there is a method that i use always, its hard-coded you can optimize it according to your example.
    Sub findMatch()

      Dim i As Integer
      Dim j As Integer
      Dim UserID As Integer
      Dim UserID2 As Integer
      Dim DeptID As Integer
      Dim DeptID2 As Integer
      Dim sal As Integer
      Dim Salary2 As Integer
      Dim Location As String
      Dim Location2 As String
    
      Dim rows1 as Integer
      Dim rows2 as Integer
    
      rows1=Worksheets("sheet1").Cells(Rows.Count, "A").End(xlUp).Row 'rows count in sheet1
      rows2=Worksheets("sheet2").Cells(Rows.Count, "A").End(xlUp).Row 'rows count in sheet2
    
        For i = 1 To rows1
            UserID = Workbooks("yourWorkBook").Worksheets("sheet1").Cells(i, "A").Value)
            'yourWorkBook is the name of the Access document
            DeptID = Workbooks("yourWorkBook").Worksheets("sheet1").Cells(i, "D").Value)
            Salary = Workbooks("yourWorkBook").Worksheets("sheet1").Cells(i, "C").Value)
            Location  = Workbooks("yourWorkBook").Worksheets("sheet1").Cells(i, "F").Value)
    
            for j= 1 to rows2
                UserID2 = Workbooks("yourWorkBook").Worksheets("sheet2").Cells(j, "A").Value)
                DeptID2 = Workbooks("yourWorkBook").Worksheets("sheet2").Cells(j, "D").Value)
                Salary2 = Workbooks("yourWorkBook").Worksheets("sheet2").Cells(j, "C").Value)
                Location2 = Workbooks("yourWorkBook").Worksheets("sheet2").Cells(j, "F").Value)
    
                If (UserID=UserID2) and (DeptID=DeptID2) Then
    
                    If Salary=Salary2 then 'userID, DeptID and Salary match
                        'you create manually another sheet (sheet3) in wich you will store the desired data
                        lstSalRow = Worksheets("sheet3").Cells(Rows.Count, "A").End(xlUp).Row 'Getting the count of rows in the sheet
                        'inserting after the last row
                        Worksheets("sheet3").Cells(lstSalRow+1, "A").Value=UserID  'Storing UserID
                        Worksheets("sheet3").Cells(lstSalRow+1, "B").Value=Salary  'Storing salary
    
                    Elseif strcmp(Location, Location2)=0 then  'userID, deptID and Location match
    
                        'Location matched : you can create another sheet (sheet4) in wich you will store the desired data
                        lstLocRow = Worksheets("sheet4").Cells(Rows.Count, "A").End(xlUp).Row
                        Worksheets("sheet4").Cells(lstLocRow+1, "A").Value=UserID 
                        Worksheets("sheet4").Cells(lstLocRow+1, "B").Value=Location
    
                    Else 'only userID and DeptID match
                        'do other actions
                    End If
    
                End If
    
            next j
    
        next i
    
    End Sub
    

    I hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: correlation matrix in r I have an excel sheet which has 700
Possible Duplicate: How to properly clean up Excel interop objects in C# I have
Possible Duplicate: VB Using colons to put two statements on same line I have
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: Copy column from one Excel sheet to another Excel sheet I have
Possible Duplicate: python: creating excel workbook and dumping csv files as worksheets How would
Possible Duplicate: Open excel document in java I have a button in my Java
Possible Duplicate: How to insert a row between two rows in an existing excel
I have customer file in Excel (using 2003) with about 16000 rows. The columns
Possible Duplicate: Excel Formula Meaning of $ I'm new to the excel macro development,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.