Solved

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

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

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…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

803 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