Solved

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

Posted on 2016-09-02
2
62 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 26

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 26

Expert Comment

by:ProfessorJimJam
ID: 41810365
.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

830 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