Compare more or less same workbooks

alexnts

New Member
Joined
Nov 2, 2017
Messages
5
Hello again!

I have four workbooks. Lets call them 2013,2014,2015,2016
Each workbook has about 7 sheets. Lets call them Tires,Parts,Doors,Windows,Computers,Consumables,*******Parts
Each sheet has about 25 columns. I am only interested in three of them. Columns A, D ,F

The values in A column are unique at each sheet, but in different order in each workbook (at the corresponding sheet of course).
On the tires sheet at each workbook values in A column starts with TIR001,TIR002 and so on.The same thing happens with other sheets. (parts sheet PAR001,Doors sheet DOO01 and so on)

So what i need to do is this.
Using the A column as my index i want to check if the data are the same across all years.

Sample data
Workbook 2013 | Sheet TIRES

Code:
A            D             F
TIR001        WRA            30
TIR010        WRB            22
TIR023        WRA            02

Starting from 2013, i want excel to parse sheet Tires, go through all A column and check the workbooks 2014|2015|2016 in the sheets Tires for values in A columns.
If a value is found (ex TIR010) then check its corresponding value in columns D and F (in 2013 is WRB and 22).If the values match do nothing.
If they differ (ex 2014 is TIR010, WRC, 03) then paint the cells in 2014 red.And so on for the other years.
Is it doable?

My regards.
I dont mind if i have to compare only two workbooks at a time.

My regards.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Are the 7 sheets always the first 7 sheets & are they always in the same order?
 
Upvote 0
If the answer to the above is yes, try this
Code:
Sub CompareBooks()

   Dim Cl As Range
   Dim Wbk As Workbook
   Dim Cnt As Long
   Dim SCnt As Long
   Dim DicAry(6) As Object
   Dim WbkAry As Variant
   
Application.ScreenUpdating = False

   WbkAry = Array("[COLOR=#0000ff]2014.xlsx[/COLOR]", "[COLOR=#0000ff]2015.xlsx[/COLOR]", "[COLOR=#0000ff]2016.xlsx[/COLOR]")
   
   For Cnt = 0 To 6
      Set DicAry(Cnt) = CreateObject("scripting.dictionary")
      With DicAry(Cnt)
         For Each Cl In Sheets(Cnt + 1).Range("A2", Sheets(Cnt + 1).Range("A" & Rows.Count).End(xlUp))
            If Not .exists(Cl.Value) Then .Add Cl.Value, Cl.Offset(, 3).Value & Cl.Offset(, 5).Value
         Next Cl
      End With
   Next Cnt
   For Cnt = LBound(WbkAry) To UBound(WbkAry)
      Set Wbk = Workbooks.Open([COLOR=#ff0000]"Z:\"[/COLOR] & WbkAry(Cnt))
      For SCnt = 0 To 6
         With DicAry(SCnt)
            For Each Cl In Sheets(SCnt + 1).Range("A2", Sheets(SCnt + 1).Range("A" & Rows.Count).End(xlUp))
               If Not .exists(Cl.Value) Then
                  Cl.Interior.Color = vbRed
               ElseIf Not .Item(Cl.Value) = Cl.Offset(, 3).Value & Cl.Offset(, 5).Value Then
                  Cl.Offset(, 3).Interior.Color = vbRed
                  Cl.Offset(, 5).Interior.Color = vbRed
               End If
            Next Cl
         End With
      Next SCnt
      Wbk.Close True
   Next Cnt
   
End Sub
This needs to go in a standard module in the 2013 workbook.
Change drive path in red & workbook names (including extension) in blue to suit
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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