Aligning identical data from two columns that have different data

jmd0103

New Member
Joined
Aug 28, 2012
Messages
10
I have two columns:
red</SPAN>
red</SPAN>
yellow</SPAN>
blue</SPAN>
teal</SPAN>
yellow</SPAN>
black </SPAN>
black </SPAN>
green</SPAN>
green</SPAN>
pink</SPAN>
pink</SPAN>
orange</SPAN>
grey </SPAN>
grey </SPAN>
white</SPAN>
brown</SPAN>
brown</SPAN>
beige</SPAN>
purple</SPAN>
purple</SPAN>
silver</SPAN>
silver</SPAN>
maroon</SPAN>
maroon</SPAN>

<TBODY>
</TBODY>

Column 1 has some data that column 2 does not have, as column 2 has some data that column 1 does not have. Both columns are in the same order however, and they must STAY in this same order. I do not wish to put it in alphabetical order. What I would like to get out of a macro is:

red</SPAN>
red</SPAN>
blue</SPAN>
yellow</SPAN>
yellow</SPAN>
teal </SPAN>
black </SPAN>
black </SPAN>
green</SPAN>
green </SPAN>
pink</SPAN>
pink</SPAN>
orange</SPAN>
grey </SPAN>
grey </SPAN>
white</SPAN>
brown</SPAN>
brown</SPAN>
beige</SPAN>
purple</SPAN>
purple</SPAN>
silver</SPAN>
silver</SPAN>
maroon</SPAN>
maroon</SPAN>

<TBODY>
</TBODY>

It needs to be able to recognize the difference between having a value missing from column 1 versus having a value missing from column 2. What I am having trouble with is after finding a non-match, I need to scan BOTH columns to see whether the value is missing from 1 or 2, and shift the other column accordingly.

Any help would be GREATLY appreciated.

Thank you!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
This should do it for you:
Code:
Sub sync_columns()
Dim rowA As Integer
Dim rowB As Integer
Dim rng As Range
    
    rowA = 1
    Do While Not IsEmpty(Range("A" & rowA))
        With Worksheets("Sheet1").Range("B:B")
            Set rng = .Find(Range("A" & rowA).Value, LookIn:=xlValues)
            If Not rng Is Nothing Then
                rowB = rng.Row
                If rowB > rowA Then
                    Range("A" & rowA & ":A" & rowB - 1).Select
                    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                    rowA = rowB
                ElseIf rowA > rowB Then
                    Range("B" & rowB & ":B" & rowA - 1).Select
                    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                End If
            End If
            rowA = rowA + 1
        End With
    Loop
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,837
Messages
6,121,883
Members
449,057
Latest member
Moo4247

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