Solved

EXCEL Match data rows in excel.  (not same amount of values)

Posted on 2016-09-02
2
56 Views
Last Modified: 2016-09-22
I have 4 columns of data.
I need the 1st row of set data in column 1 and 2 to match the first row of set data column 3 and 4
Below is an example of what the data looks like now

              COL1      COL2                                       COL3   COL4
Row 1   8810       Green                                    7228    Green
Row 2   8810           Green                                     7228     Green
Row 3   8810      Green                                      7228     Green
Row 4                                                                   7228     Green
Row 6   9086      Green                                      8810     Green
Row 7                                                                   8810     Green
Row 8                                                                     8810     Green
Row 9                                                                   8810     Green
Row 10                                                                 9044     Green
Row 11                                                                 9086     Green
Row 12                                                                 9086     Green
             
      Ideally I need the data like this
Row 1                                                                   7228   Green
Row 2                                                                   7228   Green
Row 3                                                                   7228   Green
Row 4                                                                   7228   Green
Row 5   8810 Green                                           8810   Green
Row 6   8810      Green                                           8810    Green
Row 7   8810  Green                                          8810   Green
Row 8                                                                   8810   Green
Row 9                                                                   9044   Green
Row 10  9086 Green                                          9086   Green
Row 11                                                                 9086   Green
             
      
      So essentially I need the data in col 1 and col 2 to have cells inserted only for column 1 and 2 and push that data down to where it will line up with the first row of the data set in col 3 and col 4.

I am not sure that a standard vlookup will work for this scenario,  Any ideas?
0
Comment
Question by:Julie Lyman
  • 2
2 Comments
 
LVL 25

Accepted Solution

by:
ProfessorJimJam earned 500 total points (awarded by participants)
ID: 41783257
here you go.

lets say you have four columns and your columns are from A to D

please see attached workbook.  if you run the macro or press macro shortcut key Contorl + Shift+A

it will do the job.

Sub Test()
Dim i As Long, lastrow As Long
Application.ScreenUpdating = False
 lastrow = Range("C" & Rows.Count).End(xlUp).Row

    Columns("A:D").Sort Key1:=Range("A2"), order1:=xlAscending, _
        Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
        Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    Columns("C:D").Sort Key1:=Range("C2"), order1:=xlAscending, _
        Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
        Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    i = 2 '  if your data has header. if not change to 1
    Do
        If Cells(i, "A") > Cells(i, "C") And Cells(i, "C") > "" Then
            Cells(i, "A").Resize(1, 2).Insert xlShiftDown
        ElseIf Cells(i, "A") < Cells(i, "C") And Cells(i, "A") > "" Then
            Cells(i, "C").Resize(1, 2).Insert xlShiftDown
        End If
        i = i + 1
    Loop Until Cells(i, "A") = "" And Cells(i, "C") = ""
Application.ScreenUpdating = True
End Sub

Open in new window

EE.xlsm
0
 
LVL 25

Expert Comment

by:ProfessorJimJam
ID: 41810365
.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now