Solved

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

Posted on 2016-09-02
2
45 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)
Comment Utility
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
Comment Utility
.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

763 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

11 Experts available now in Live!

Get 1:1 Help Now