Comparison of Data between Worksheets Same Workbook

jumpmanz5

New Member
Joined
Dec 3, 2007
Messages
14
I'm not an excel power user by any means, so i'm having trouble getting a column in one worksheet to compare against the same column in another worksheet.

I have two different worksheets in the same workbook each sheet contains a different data with the exception of one column. The columns contains a five digit number and between the two columns the cells in the row may or may not be the match and not be in sequential order.

What I would like to preform as an example would be the comparison of Column A in worksheet 1 to Column A (or whatever column the data is in) of worksheet 2. Two options in returning value would be fine although one is preferred.

Example
Worksheet 1.

Rows Column A
Row 1 12345
Row 2 67890
Row 3 09876
Row 4 54321

Worksheet 2

Rows Column A
Row 1 12345 – Matches Worksheet 1 Row 1
Row 2 75984
Row 3 09876
Row 4 67890 – Matches Worksheet 1 Row 2
Row 5 15935
Row 6 09876 – Matches Worksheet 1 Row 3
Row 7 78963
Row 8 67890 – Matches Worksheet 1 Row 2
Row 9 09876 – Matches Worksheet 1 Row 3
Row 10 78963
Row 11 54321 – Matches Worksheet 1 Row 4


Desired Result 1 (Preferred) – Any item in Worksheet 2 Column A that matched a number in Worksheet 1 Column A, the entire record (entire row of data) would be pulled from Worksheet 2 and put into a new worksheet 3.

Worksheet 3 – Would like look this; only the rows that matched a number in worksheet 1 pulled over. When I say entire row I mean columns A through M work of data.

Rows Column A
Row 1 12345 – Matched Worksheet 1 Row 1
Row 4 67890 – Matched Worksheet 1 Row 2
Row 6 09876 – Matched Worksheet 1 Row 3
Row 8 67890 – Matched Worksheet 1 Row 2
Row 9 09876 – Matched Worksheet 1 Row 3
Row 11 54321 – Matched Worksheet 1 Row 4

Desired Result 2 – Any item in Worksheet 2 Column A that matched a number in Worksheet 1 Column A, the number in Worksheet 2 Column A would highlight.

Worksheet 3 – Would like look this

Rows Column A
Row 1 12345 – Number would highlight because of match to Worksheet 1 Row 1
Row 2 75984
Row 3 09876
Row 4 67890 – Number would highlight because of match to Row 2
Row 5 15935
Row 6 09876 – Number would highlight because of match to Row 3
Row 7 78963
Row 8 67890 – Number would highlight because of match to Row 2
Row 9 09876 – Number would highlight because of match to Row 3
Row 10 78963
Row 11 54321 – Number would highlight because of match to Row 4


I don't know if this needs to be a conditional formatting item or VBA, etc. I would greatly apprecaite any help anyone could provided. I'm staring at a wall.

Jump
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
jumpmanz5,

What version of Excel are you using?

If this was a problem where one needed to use your data, anyone trying to help you would have to enter the data manually. That makes no sense.

Can you post a screenshot of the three worksheets, and, post a screenshot of the worksheet results (manually formatted by you) that you are looking for?

To post your data, you can download and install one of the following two programs:
Excel Jeanie
MrExcel HTML Maker


If you are not able to give us screenshots:
You can upload your workbook to Box Net,
sensitive changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Upvote 0
I'm using Microsoft 2010.

I'm not concerned that anyone using my data, as the results will be the only information I send to anyone.

Essentially, I have a workbook that 1) contains every contract records (thousands) within my company (Worksheet 1), which can be sorted by business group (BG) (we have eight BG), and 2) a list of every subcontract record within the company(Worksheet 2).

What I'm looking to do is sort data by BG and then take that data (which would be Column A info) and compare against all the subcontract data information. The columns A would be the only column within each worksheet that would match.

I'm at work at the moment, so i'm not able to install any software, but should be able to do it one i get home a little later this evening.

If this helps at all the data would be similar to this.

Columns – Worksheet 1
A | B | C | D | E | F
01985 | ABC Company | $7,000 | 8/12/2013 | 12/31/2013 | Yes
32165 | XYZ Company | $3,000 | 8/11/2013 | 12/31/2013 | Yes
35468 | DFE Company | $8,000 | 8/6/2013 | 12/31/2013 | Yes
15963 | UYX Company | $4,000 | 8/1/2013 | 12/31/2013 | Yes


Columns – Worksheet 2
A | B | C | D | E | F
01985 | 951 Company | $9,000 | 8/5/2013 | 12/31/2013 | Yes
32165 | 753 Company | $2,000 | 8/9/2013 | 12/31/2013 | Yes
35468 | DFE Company | $7,000 | 8/7/2013 | 12/31/2013 | Yes
15963 | 342 Company | $6,000 | 8/3/2013 | 12/31/2013 | Yes

Results to Worksheet 3
A | B | C | D | E | F
35468 | DFE Company | $8,000 | 8/6/2013 | 12/31/2013 | Yes

The results would only be one record, since only the 35468 matched between the two other sheets.

The number in Column A is a project number. All other data between the two sheets are completely different with the exception of that one column a 5 digit numbers. I’m pulling each report from different systems and putting them into the same workbook (different worksheets). Just looking for an easier way to pull out all the records for subcontracts info that matches that project number from the contract info.

I hope that adds a little clarification.
 
Last edited:
Upvote 0
jumpmanz5,

It would appear that you are looking for matches in Sheet1 columns A&B to Sheet2 columns A&B.

I'm at work at the moment, so i'm not able to install any software, but should be able to do it one i get home a little later this evening.

I would prefer not to have to split your dataset, so, I will wait until later.
 
Upvote 0
Hiker95

Here are is a sample of the worksheet data.

Worksheet 1 - The highlight show the vehicle record that match to records within Sheet 2.


Excel 2010
ABCDEFGHIJKLM
1Purchase OrderPO Release NumberPO Status TypeBuyerPO Total AmountVendor NameStart DateEnd DateVehiclePrime Contract No.Program NamePMVendor Sales Order
2APG-1235970OSmith$2,860,900.00Subcontractor 19/4/20121/17/201405872Prime Contract 11Program 55PM 1
3APG-1235990OSmith$644,800.00Subcontractor 29/11/20121/17/201409169Prime Contract 12Program 56PM 21XXXXXC
4APG-1236010OSmith$330,000.00Subcontractor 39/28/20121/17/201405577Prime Contract 13Program 57PM 31XXXXXC
5APG-1236010OSmith$330,000.00Subcontractor 49/28/20121/17/2014INDIRPrime Contract 14Program 58PM 41XXXXXC
6APG-1236020OSmith$2,412,840.00Subcontractor 59/11/20121/17/201409169Prime Contract 15Program 59PM 51XXXXXC*
7APG-1253300OSmith$382,800.00Subcontractor 69/4/20121/17/201405577Prime Contract 16Program 60PM 61XXXXXC
8APG-1254290OSmith$308,625.00Subcontractor 79/10/20121/17/201409169Prime Contract 17Program 61PM 71XXXXXC
Sheet 1



Worksheet 2 - The highlights show the vehicle records that match in Worksheet 1


Excel 2010
ABCDEFGHIJKLMNOPQRSTU
1Vehicle #Proj/BPA #Call Order #NameVeh TypeCACI CompanyPrimePrime Contract #SubK #Cust Level 1Vehicle ManagerProject ManagerContracts ManagerSubK ManagerPOP (Start)POP (End)Final Opt End DtPotentialCeilingFundedStage
2047730587Product 1Contract Type 1Company 1MY CompanyContract 1Customer 1PM 1CM 1
305411Product 2Contract Type 2Company 2MY CompanyContract 2Customer 2PM 2CM 2
405518Product 3Contract Type 3Company 3MY CompanyContract 3Customer 3PM 3CM 3
50557741004101Product 4Contract Type 4Company 4MY CompanyContract 4Customer 4PM 4CM 4
60557745004502Product 5Contract Type 5Company 5MY CompanyContract 5Customer 5PM 5CM 5
705751Product 6Contract Type 6Company 6MY CompanyContract 6Customer 6PM 6CM 6
8058720010Product 7Contract Type 7Company 7MY CompanyContract 7Customer 7PM 7CM 7
Sheet2


Worksheet 3 - Results - This sheet would only show records from Worksheet 1 where the vehicle matched a vehicle number in Worksheet 2.


Excel 2010
ABCDEFGHIJKLM
1Purchase OrderPO Release NumberPO Status TypeBuyerPO Total AmountVendor NameStart DateEnd DateVehiclePrime Contract No.Program NamePMVendor Sales Order
2APG-1235970OSmith$2,860,900.00Subcontractor 19/4/20121/17/201405872Prime Contract 11Program 55PM 1
3APG-1236010OSmith$330,000.00Subcontractor 39/28/20121/17/201405577Prime Contract 13Program 57PM 31XXXXXC
4APG-1253300OSmith$382,800.00Subcontractor 69/4/20121/17/201405577Prime Contract 16Program 60PM 61XXXXXC
Sheet3


I really how this helps clarify what i'm looking to compare and how i would like the results to return.

Please let me know if you need more information.

Thank You
 
Upvote 0
jumpmanz5,

Thanks for the screenshots.

Sample worksheets:


Excel 2007
ABCDEFGHIJKLM
1Purchase OrderPO Release NumberPO Status TypeBuyerPO Total AmountVendor NameStart DateEnd DateVehiclePrime Contract No.Program NamePMVendor Sales Order
2APG-1235970OSmith$2,860,900.00Subcontractor 19/4/20121/17/20145872Prime Contract 11Program 55PM 1
3APG-1235990OSmith$644,800.00Subcontractor 29/11/20121/17/20149169Prime Contract 12Program 56PM 21XXXXXC
4APG-1236010OSmith$330,000.00Subcontractor 39/28/20121/17/20145577Prime Contract 13Program 57PM 31XXXXXC
5APG-1236010OSmith$330,000.00Subcontractor 49/28/20121/17/2014INDIRPrime Contract 14Program 58PM 41XXXXXC
6APG-1236020OSmith$2,412,840.00Subcontractor 59/11/20121/17/20149169Prime Contract 15Program 59PM 51XXXXXC*
7APG-1253300OSmith$382,800.00Subcontractor 69/4/20121/17/20145577Prime Contract 16Program 60PM 61XXXXXC
8APG-1254290OSmith$308,625.00Subcontractor 79/10/20121/17/20149169Prime Contract 17Program 61PM 71XXXXXC
9
Sheet1



Excel 2007
ABCDEFGHIJKLM
1Vehicle #Proj/BPA #Call Order #NameVeh TypeCACI CompanyPrimePrime Contract #SubK #Cust Level 1Vehicle ManagerProject ManagerContracts Manager
24773587Product 1Contract Type 1Company 1MY CompanyContract 1Customer 1PM 1CM 1
35411Product 2Contract Type 2Company 2MY CompanyContract 2Customer 2PM 2CM 2
45518Product 3Contract Type 3Company 3MY CompanyContract 3Customer 3PM 3CM 3
5557741004101Product 4Contract Type 4Company 4MY CompanyContract 4Customer 4PM 4CM 4
6557745004502Product 5Contract Type 5Company 5MY CompanyContract 5Customer 5PM 5CM 5
75751Product 6Contract Type 6Company 6MY CompanyContract 6Customer 6PM 6CM 6
8587210Product 7Contract Type 7Company 7MY CompanyContract 7Customer 7PM 7CM 7
9
Sheet2


The output sheet, Sheet3, rows 2 to the last used row will be cleared first, then the resulting data will be posted:


Excel 2007
ABCDEFGHIJKLM
1Purchase OrderPO Release NumberPO Status TypeBuyerPO Total AmountVendor NameStart DateEnd DateVehiclePrime Contract No.Program NamePMVendor Sales Order
2APG-1235970OSmith$2,860,900.00Subcontractor 19/4/20121/17/20145872Prime Contract 11Program 55PM 1
3APG-1236010OSmith$330,000.00Subcontractor 39/28/20121/17/20145577Prime Contract 13Program 57PM 31XXXXXC
4APG-1253300OSmith$382,800.00Subcontractor 69/4/20121/17/20145577Prime Contract 16Program 60PM 61XXXXXC
5
Sheet3


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Option Explicit
Sub FindMatchingVehicles()
' hiker95, 08/31/2013
' http://www.mrexcel.com/forum/excel-questions/723481-comparison-data-between-worksheets-same-workbook.html
Dim a As Variant, r As Long, lr As Long, n As Long, fr As Long, nr As Long
Application.ScreenUpdating = False
With Sheets("Sheet3")
  lr = .Cells(Rows.Count, 1).End(xlUp).Row
  If lr > 1 Then
    .Range("A2:M" & lr).ClearContents
  End If
End With
With Sheets("Sheet1")
  a = .Cells(1).CurrentRegion
  lr = .Cells(Rows.Count, 1).End(xlUp).Row
  .Range("A2:M" & lr).Sort key1:=.Range("I2"), order1:=2
  For r = 2 To lr
    n = Application.CountIf(.Columns(9), .Cells(r, 9).Value)
    fr = 0
    On Error Resume Next
    fr = Application.Match(.Cells(r, 9), Sheets("Sheet2").Columns(1), 0)
    On Error GoTo 0
    If fr > 0 Then
      nr = Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1).Row
      Sheets("Sheet3").Range("A" & nr & ":M" & nr).Resize(n) = .Range("A" & r & ":M" & r + n - 1).Value
    End If
    r = r + n - 1
  Next r
  .Cells(1).CurrentRegion = a
End With
With Sheets("Sheet3")
  .Range(.Cells(2, 5), .Cells(nr, 5)).NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
  .Range(.Cells(2, 7), .Cells(nr, 8)).NumberFormat = "m/d/yyyy"
  .Range(.Cells(2, 2), .Cells(nr, 4)).HorizontalAlignment = xlCenter
  .Range(.Cells(2, 6), .Cells(nr, 9)).HorizontalAlignment = xlCenter
  .Columns.AutoFit
  .Activate
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the FindMatchingVehicles macro.
 
Last edited:
Upvote 0
Hiker95... thank you so much. I'll try this on Tuesday once i'm in the office and report back on how it worked. I really do appreciate it.

Jump
 
Upvote 0
Hiker 95...

I can't think you enough for putting that together... Worked like a champ.

My only question is in regards to the three sheet that is created by the macro. Is it an easy tweak to the macro if i wanted the sheet created to include more columns. For example: When I ran the macro it in the new sheet it produced info for columns A-M. Would it be possible to extend that so the results would be say A-R. Only reason i'm asking, as I can see using the macro in other spreadsheet with the same data, but pulling quick reports with more info.

Thanks
Jump
 
Upvote 0
jumpmanz5,

I can't think you enough for putting that together... Worked like a champ.

Thanks for the feedback.

You are very welcome. Glad I could help.


Would it be possible to extend that so the results would be say A-R.

Be back in a little while.
 
Upvote 0
jumpmanz5,

Would it be possible to extend that so the results would be say A-R.

Give the following a try:

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Option Explicit
Sub FindMatchingVehiclesV2()
' hiker95, 09/04/2013
' http://www.mrexcel.com/forum/excel-questions/723481-comparison-data-between-worksheets-same-workbook.html
Dim a As Variant, r As Long, lr As Long, n As Long, fr As Long, nr As Long
Application.ScreenUpdating = False
With Sheets("Sheet3")
  lr = .Cells(Rows.Count, 1).End(xlUp).Row
  If lr > 1 Then
    .Range("A2:R" & lr).ClearContents
  End If
End With
With Sheets("Sheet1")
  a = .Cells(1).CurrentRegion
  lr = .Cells(Rows.Count, 1).End(xlUp).Row
  .Range("A2:R" & lr).Sort key1:=.Range("I2"), order1:=2
  For r = 2 To lr
    n = Application.CountIf(.Columns(9), .Cells(r, 9).Value)
    fr = 0
    On Error Resume Next
    fr = Application.Match(.Cells(r, 9), Sheets("Sheet2").Columns(1), 0)
    On Error GoTo 0
    If fr > 0 Then
      nr = Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1).Row
      Sheets("Sheet3").Range("A" & nr & ":R" & nr).Resize(n) = .Range("A" & r & ":R" & r + n - 1).Value
    End If
    r = r + n - 1
  Next r
  .Cells(1).CurrentRegion = a
End With
With Sheets("Sheet3")
  .Range(.Cells(2, 5), .Cells(nr, 5)).NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
  .Range(.Cells(2, 7), .Cells(nr, 8)).NumberFormat = "m/d/yyyy"
  .Range(.Cells(2, 2), .Cells(nr, 4)).HorizontalAlignment = xlCenter
  .Range(.Cells(2, 6), .Cells(nr, 9)).HorizontalAlignment = xlCenter
  .Columns.AutoFit
  .Activate
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the FindMatchingVehiclesV2 macro.
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,619
Members
449,039
Latest member
Mbone Mathonsi

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