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
 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

hiker95

Well-known Member
Joined
Apr 8, 2009
Messages
17,649
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.
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
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
 

sabla

New Member
Joined
Apr 1, 2015
Messages
3
Thank you, Mick.

That was exactly what i need.

Best regards,
Alex
 

Watch MrExcel Video

Forum statistics

Threads
1,102,582
Messages
5,487,685
Members
407,608
Latest member
kjw

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top