Comparing column from different workbooks

ace2ace234

New Member
Joined
Sep 30, 2014
Messages
12
Hi All,

I hope you guys can help me out,

I am trying to create a macro to compare column C in my workbook1 to column C in workbook2 and for it to highlight in red what is missing.

I basically have a delivery report I run which tells me what deliveries(This is a delivery number) I have each week and we have a manual log that we use where we enter delivery details including delivery number,I want to run report and have a macro saved into the log so I can make sure that the delivery number in the report is also in the log.

I hope this makes sense,
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Apologies I never added the code I am working with,I have got it work in a way but am a bit stuck to the final part I need,

The lists I am comparing are not in order and will never be,I need it to check if part is not in column on first sheet is anywhere in column on 2nd sheet that is shows the value.

See code below:

<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Sub Compare()
Dim Rng1 As Range
Dim Rng2 As Range
Dim Dn As Range
Dim n As Long
Dim i As Long
Dim j As Long
Dim temp As String
Dim Dic As Object
Dim c As Long
Dim Ray()
Dim R As Variant
With Sheets("Sheet1")
Set Rng1 = .Range(.Range("C3"), .Range("c" & Rows.Count).End(xlUp))
End With
Dim wb1 As Workbook, sh1 As Worksheet
Set wb1 = Workbooks(InputBox("enter b1"))
Set sh1 = wb1.Sheets(InputBox("enter s1"))


With Sheets("Sheet2")
Set Rng2 = .Range(.Range("C3"), .Range("C" & Rows.Count).End(xlUp))
End With
Set Dic = CreateObject("scripting.dictionary")
For Each Dn In Rng2: Dic(Dn.Value) = Empty: Next
For Each Dn In Rng1
If Not Dic.exists(Dn.Value) Then
ReDim Preserve Ray(c)
Ray(c) = Dn
c = c + 1
End If
Next
Dic.RemoveAll
For Each R In Ray: Dic(R) = Empty: Next
ReDim Ray(1 To Dic.Count)
Ray = Dic.keys
For i = 0 To UBound(Ray)
For j = i To UBound(Ray)
If Ray(j) < Ray(i) Then
temp = Ray(i)
Ray(i) = Ray(j)
Ray(j) = temp
End If
Next j
Next i
MsgBox "Missing Numbers" & vbCrLf & "from Sheet 2 = " & vbCrLf & Join(Ray, vbCrLf)
End Sub

</code>
 
Upvote 0

Forum statistics

Threads
1,196,181
Messages
6,013,906
Members
441,792
Latest member
elcafe31

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