Matching data in Excel nd add rows to line up

cat57

New Member
Joined
Sep 5, 2014
Messages
4
Hello,

I'm new at this so please bear with me. I have a large amount of data that I need to compare and match in Excel and cannot figure out how to do it.
I need to compare the data in column A to column F, get them to line up when they match and insert a row, leaving it blank, if there is no match. Any help would be greatly appreciated! Thanks!

This is a sample of the data and the results I need are below it:
186508901/02/1401/02/147517SDC186508901/02/1401/02/147517
186947801/01/1401/01/141113INO186947801/01/1401/01/14913
187323201/08/1401/10/1416162SDC187353601/04/1401/04/14971
187353601/04/1401/04/14971INO187362401/15/1401/15/14606
187362401/15/1401/15/14606INO187554001/10/1401/10/141955
187554001/10/1401/10/141955INO187887401/05/1401/05/1412654
187861601/08/1401/10/142311SDC187956701/06/1401/06/145648
187887401/05/1401/05/145485SDC
187956701/06/1401/06/145648SDC
What I need:
186508901/02/1401/02/147517SDC186508901/02/1401/02/147517
186947801/01/1401/01/141113INO186947801/01/1401/01/14913
187323201/08/1401/10/1416162SDC
187353601/04/1401/04/14971INO187353601/04/1401/04/14971
187362401/15/1401/15/14606INO187362401/15/1401/15/14606
187554001/10/1401/10/141955INO187554001/10/1401/10/141955
187861601/08/1401/10/142311SDC
187887401/05/1401/05/145485SDC187887401/05/1401/05/1412654
187956701/06/1401/06/145648SDC187956701/06/1401/06/145648

<COLGROUP><COL style="WIDTH: 69pt" width=92><COL style="WIDTH: 69pt" span=2 width=92><COL style="WIDTH: 69pt" span=6 width=92><TBODY>
</TBODY>
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
A simple vlookup will do what you require. Put the first table in sheet1 and the first 'half' of the table in another sheet, columns A:E.

Then in F1:
=IFERROR(VLOOKUP($A1,Sheet1!$F:$I,1,0),"")
G1:
=IFERROR(VLOOKUP($A1,Sheet1!$F:$I,2,0),"")
H1:
=IFERROR(VLOOKUP($A1,Sheet1!$F:$I,3,0),"")
I1:
=IFERROR(VLOOKUP($A1,Sheet1!$F:$I,4,0),"")

Copy down as far as required
 
Upvote 0
cat57,

Welcome to the MrExcel forum.

1. What version of Excel and Windows are you using?

2. Are you using a PC or a Mac?


With your raw data in columns A thru E, sorted/grouped by column A, and, the data in columns F thru I, sorted/grouped by column F.


Sample raw data:


Excel 2007
ABCDEFGHI
118650891/2/20141/2/20147517SDC18650891/2/20141/2/20147517
218694781/1/20141/1/20141113INO18694781/1/20141/1/2014913
318732321/8/20141/10/201416162SDC18735361/4/20141/4/2014971
418735361/4/20141/4/2014971INO18736241/15/20141/15/2014606
518736241/15/20141/15/2014606INO18755401/10/20141/10/20141955
618755401/10/20141/10/20141955INO18788741/5/20141/5/201412654
718786161/8/20141/10/20142311SDC18795671/6/20141/6/20145648
818788741/5/20141/5/20145485SDC
918795671/6/20141/6/20145648SDC
10
Sheet1


After the macro:


Excel 2007
ABCDEFGHI
118650891/2/20141/2/20147517SDC18650891/2/20141/2/20147517
218694781/1/20141/1/20141113INO18694781/1/20141/1/2014913
318732321/8/20141/10/201416162SDC
418735361/4/20141/4/2014971INO18735361/4/20141/4/2014971
518736241/15/20141/15/2014606INO18736241/15/20141/15/2014606
618755401/10/20141/10/20141955INO18755401/10/20141/10/20141955
718786161/8/20141/10/20142311SDC
818788741/5/20141/5/20145485SDC18788741/5/20141/5/201412654
918795671/6/20141/6/20145648SDC18795671/6/20141/6/20145648
10
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub AlignData()
' hiker95, 09/05/2014, ME803639
Dim r As Long, lr As Long, d As Range
Application.ScreenUpdating = False
lr = Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row
Set d = Range("A1:A" & lr)
r = 1
Do While d.Cells(r, 1) <> ""
  If d.Cells(r, 1).Offset(, 5) <> "" Then
    If d.Cells(r, 1) < d.Cells(r, 1).Offset(, 5) Then
      d.Cells(r, 1).Offset(, 5).Resize(, 4).Insert -4121
    ElseIf d.Cells(r, 1) > d.Cells(r, 5).Offset(, 1) Then
      d.Cells(r, 1).Resize(, 5).Insert -4121
      lr = lr + 1
      Set d = Range("A1:A" & lr)
    End If
  End If
  r = r + 1
Loop
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the AlignData macro.
 
Upvote 0
Hi,

I'm using a PC and Excel 2010 - will try your macro and let you know how it goes

Thanks.
 
Upvote 0
Works great! Thank you so much for your help!
One last question; how do I save the macro for continued use so I don't have to keep copying and pasting? Thanks.
 
Upvote 0
cat57,

Works great! Thank you so much for your help!

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.


One last question; how do I save the macro for continued use so I don't have to keep copying and pasting?

I am not familiar with Excel 2010, but, I am sure that you can save the macro in your VBAProject(PERSONAL.XLSB) file, in a code Module.

If you go into the VBA Editor, see if you have a VBAProject(PERSONAL.XLSB) file.

If not see if the following link will help you create it:

How do I create and use a PERSONAL file for my VBA code
How do I create and use a PERSONAL file for my VBA code


You can then add my macro code, and, be able to run the macro from your VBAProject(PERSONAL.XLSB) file.
 
Last edited:
Upvote 0
Hi Hiker95,

That macros is brilliant! Can it be applied to 3 sets of data?

1. I have a PC.
2. I am using Excel2010.

Here is my sample data:

The first set of data is shown in columns A-C, the second set is columns E-G, and 3rd set is columns I-K. The data should be sorted and matched by Asset # (Columns A, E & I).

AB CDEF GHIJ K
1ASSET #ASSET DESCRIPTION COSTASSET #ASSET DESCRIPTION COSTASSET #ASSET DESCRIPTION COST
20001WAREHOUSE 10,000,0000001WAREHOUSE 10,000,0000006YARD TRACTOR 40,000
30002OFFICE BLDG 2,000,0000002OFFICE BLDG 2,000,0000007FORKLIFT 20,000
40003GARAGE 3,000,0000003GARAGE 3,000,0000008CHEVY VAN 20,000
5000414 ACRE CORP CAMPUS 5,000,000000414 ACRE CORP CAMPUS 5,000,0000012COPIER 1,000
60005GMC PICKUP TRUCK 20,0000005GMC PICKUP TRUCK 20,0000014SCISSOR LIFT 10,000
70006YARD TRACTOR 40,0000006YARD TRACTOR 40,0000001WAREHOUSE 10,000,000
80007FORKLIFT 20,0000007FORKLIFT 20,0000002OFFICE BLDG 2,000,000
90008CHEVY VAN 20,0000008CHEVY VAN 20,0000003GARAGE 3,000,000
100009CONFERENCE DESK 1,0000009CONFERENCE DESK 1,000000414 ACRE CORP CAMPUS 5,000,000
110010PHONE SYSTEM 2,0000010PHONE SYSTEM 2,0000005GMC PICKUP TRUCK 20,000
120011REFRIGERATOR 1,0000012COPIER 1,0000009CONFERENCE DESK 1,000
130012COPIER 1,0000013MERCHANDISE PICKER 10,000,0000013MERCHANDISE PICKER 10,000,000
140013MERCHANDISE PICKER 10,000,0000014SCISSOR LIFT 10,0000017DELL 300 1,000
150014SCISSOR LIFT 10,0000015LABEL READER 100,000
160015LABEL READER 100,0000017DELL 300 1,000
170016CONVEYOR 1,000,0000018INTEL SPIRON 1,000
180017DELL 300 1,000
190018INTEL SPIRON 1,000
200019PACKER II SOFTWARE 5,000
210020PACKER SOFTWARE UPGARDE 3,000

<tbody>
</tbody>

Thank you in advance! First time poster, so if I need to clean up my sample data, just let me know.
 
Upvote 0
jennifer865,

Welcome to the MrExcel forum.

That macros is brilliant!

Thanks for the feedback, and, kudos.

Can it be applied to 3 sets of data?

No, but I do have another way to solve your request.


To start with:

Your raw data is not the same as cat57's.

Please do not post your questions in threads started by others - - this is known as thread hijacking.

Always start a new thread for your questions and, if you think it helps, provide a link to any other thread as a reference.

Start a new thread for your question and be sure to give it a search friendly title that accurately describes your need.

In your New Thread include:
1. the version of Windows, and, Excel you are using
2. Are you using a PC or a Mac?

So that we can get it right on the first try:

Can you post a screenshot of the actual raw data worksheet?

And, can you post a screenshot of the worksheet results (manually formatted by you) that you are looking for?

To post a small screen shot try one of the following:

Excel Jeanie
Download

MrExcel HTML Maker
https://onedrive.live.com/?cid=8cffdec0ce27e813&sc=documents&id=8CFFDEC0CE27E813!189

Borders-Copy-Paste
http://www.mrexcel.com/forum/about-board/444901-how-create-table-like-aladin.html#post2198045

To test the above:
Test Here


Or, you can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.


Then send me a Private Message, with a link to this thread as a reference, and, a link to your new thread, and, I will have a look.
 
Upvote 0

Forum statistics

Threads
1,207,094
Messages
6,076,550
Members
446,212
Latest member
KJAYPAL200

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top