Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-09-02
2
Medium Priority
?
77 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 27

Accepted Solution

by:
ProfessorJimJam earned 2000 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 27

Expert Comment

by:ProfessorJimJam
ID: 41810365
.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

876 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