Comparing two columns to another two columns with similar data

sabla

New Member
Joined
Apr 1, 2015
Messages
3
Hello everybody,

I need to compare two areas with two columns each . First column is full of dates, and the second has names in it. Both columns in both areas are already sorted A to Z.
Areas are similar to each other, but some names/dates combinations can appear in one area, and not in another.
Needless to say, I can not merge both columns into one and compare only two columns instead of four, due to already too big file size.
I need a code that compares all 4 columns. If both columns are with same data, do nothing, but if something is on the left (and not on the right) then do sub1 (insert row on the right), and if something is on the right (and not on the left) then do sub2 (insert row on the left). I don't need these two codes for sub1, and sub2. I wrote them already.

Example:
start - input data
http://oi57.tinypic.com/2v3n6l1.jpg

finish - output data
http://oi60.tinypic.com/317cbia.jpg

Thank you all,
Alex
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
sabla,

Welcome to the MrExcel forum.

1. What version of Excel, and, Windows are you using?

2. Are you using a PC or a Mac?


You are posting pictures/graphics/PNG files. This means that 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.


To start off, and, so that we can get it right on the first try:

Can you post a screenshot of the actual raw data worksheet?

And, can you post a screenshot of the worksheet results (manually formatted by you) that you are looking for?

To post a small screen shot (NOT a graphic, or, picture, or, flat text) try one of the following:

MrExcel HTML Maker
If you do not know how to install and how to use HTML Mr.Excel Maker
https://www.youtube.com/watch?v=JycvgGppxt0&feature=youtu.be

Excel Jeanie
Download

Borders-Copy-Paste
http://www.mrexcel.com/forum/about-board/444901-how-create-table-like-aladin.html#post2198045

To test the above:
Test Here


Or, you can upload your workbook to (the BLUE link-->) Box Net ,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Upvote 0
Try this for data in "A & B" and "C & D" for results starting F1"
Code:
[COLOR="Navy"]Sub[/COLOR] MG01Apr10
[COLOR="Navy"]Dim[/COLOR] RngA [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] oval, oMax
[COLOR="Navy"]Dim[/COLOR] RngB [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] col [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
[COLOR="Navy"]Dim[/COLOR] ColA, ColB
[COLOR="Navy"]Dim[/COLOR] Q
[COLOR="Navy"]Set[/COLOR] RngA = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
    [COLOR="Navy"]Set[/COLOR] RngB = Range(Range("B2"), Range("B" & Rows.Count).End(xlUp))
        oMax = Application.Max(RngA.Count, RngB.Count)
            [COLOR="Navy"]Set[/COLOR] RngA = Range("A1").Resize(oMax + 1)
                ReDim Ray(1 To RngA.Count * 2, 1 To 4)


[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] RngA
            [COLOR="Navy"]For[/COLOR] col = 1 To 2
                oval = IIf(col = 1, Dn.Value & "," & Dn.Offset(, 1), Dn.Offset(, 2) & "," & Dn.Offset(, 3))
                [COLOR="Navy"]If[/COLOR] Not .Exists(oval) [COLOR="Navy"]Then[/COLOR]
                    [COLOR="Navy"]If[/COLOR] col = 1 [COLOR="Navy"]Then[/COLOR]
                        ColA = 1: ColB = 0
                    [COLOR="Navy"]Else[/COLOR]
                        ColB = 1: ColA = 0
                    [COLOR="Navy"]End[/COLOR] If
                    .Add oval, Array(ColA, ColB, 1)
                [COLOR="Navy"]Else[/COLOR]
                    Q = .Item(oval)
                    [COLOR="Navy"]If[/COLOR] col = 1 [COLOR="Navy"]Then[/COLOR]
                        Q(0) = Q(0) + 1
                    [COLOR="Navy"]ElseIf[/COLOR] col = 2 [COLOR="Navy"]Then[/COLOR]
                        Q(1) = Q(1) + 1
                    [COLOR="Navy"]End[/COLOR] If
                    Q(2) = Application.Max(Q(0), Q(1))
                    .Item(oval) = Q
                [COLOR="Navy"]End[/COLOR] If
            [COLOR="Navy"]Next[/COLOR] col
        [COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]Dim[/COLOR] k [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Dim[/COLOR] rw [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Bc [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]


[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] k [COLOR="Navy"]In[/COLOR] .keys
    [COLOR="Navy"]For[/COLOR] n = 1 To .Item(k)(2)
        rw = rw + 1
        Ray(rw, 1) = IIf(n > .Item(k)(0), "", Format(Split(k, ",")(0), "dd_mmm"))
        Ray(rw, 2) = IIf(n > .Item(k)(0), "", Split(k, ",")(1))
        Ray(rw, 3) = IIf(n > .Item(k)(1), "", Format(Split(k, ",")(0), "dd_mmm"))
        Ray(rw, 4) = IIf(n > .Item(k)(1), "", Split(k, ",")(1))
    [COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]Next[/COLOR] k
Range("F1").Resize(rw, 4) = Ray
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,122
Members
448,550
Latest member
CAT RG

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