Combining data from two spreadsheets

symphonic

New Member
Joined
Jun 24, 2011
Messages
14
I have two spreadsheets. They share data in four columns (first name, last name, title, company). One spreadsheet also has an ID number column, the other has a Business Type column.

The rows don't synch up (there are 32,000 rows). I need to combine these spreadsheets into a single document so that each row has all of the relevant data--I need to match on first name, last name, title, and company, and then add either the business type or the ID number based on the matches.

Can anyone help? I'm totally new to macros, I've worked with formulas, and I don't have MS Access.

Thanks!
Steve
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
symphonic,

Welcome to the MrExcel forum.

What version of Excel are you using?

You will generally get much more help (and faster) in this forum if you can post your small samples (what you have and what you expect to achieve) directly in the forum.

To attach screenshots, see below in my Signature block: Post a screen shot with one of these:
 
Upvote 0
Thanks, Hiker95. Bleow are two screenshots--columns are identical with the exception of Business Type one spreadsheet, and ID on the other spreadsheet.


Challenge is to combine this data onto a single spreadsheet. The two spreadsheets do not line up exactly and there are approximately 32,000 rows.


Thanks,
Steve
Excel Workbook
ABCDEF
1First NameLast NameTitleAccount NameBusiness TypeContact ID
2LawrenceAaronsonPARTNERMcDonnell Boehnen Hulbert & BerghoffLaw Firm, Private Attorneys
3RachelAaronsonASSOCIATEMcDermott Will & EmeryPrivate Attorneys
4EricAarrestadWatchGuardTechnology
5JesseAbairASSOCIATERackemann, Sawyer & BrewsterPrivate Attorneys
6StephenAbarbanelCOUNSELRobinson & ColePrivate Attorneys
7FredAbaroaCMOCosta Vida Fresh Mexican GrillFood & Beverage
8RichardAbatiPARTNERChoate Hall & Stewart LLPLaw Firm, Private Attorneys
9JafferAbbasiASSOCIATEHunton & WilliamsPrivate Attorneys
10GailAbbeyASSOCIATEEdwards Angell Palmer & DodgePrivate Attorneys
Incl Bus. Type
Excel 2010
Excel Workbook
ABCDEF
1First NameLast NameTitleAccount NameBusiness TypeContact ID
2LawrenceAaronsonPARTNERMcDonnell Boehnen Hulbert & Berghoff0038000000Z3qFU
3EricAarrestadWatchGuard0038000000fnLIa
4JesseAbairASSOCIATERackemann, Sawyer & Brewster0038000000Z3tlW
5StephenAbarbanelCOUNSELRobinson & Cole0038000000Z3tm1
6FredAbaroaCMOCosta Vida Fresh Mexican Grill0038000000Z3iS6
7RichardAbatiPARTNERChoate Hall & Stewart LLP0038000000Z3tSt
8JafferAbbasiASSOCIATEHunton & Williams0038000000Z3uML
9GailAbbeyASSOCIATEEdwards Angell Palmer & Dodge0038000000Z3tVV
10TonyAbbinanteDirector Trade & Community RelationsDiageo0038000000t03lk
Incl ID
Excel 2010
 
Upvote 0
symphonic,

Are we working with two separate workbooks?

Or, are we working with one workbook containing two worksheets?
 
Upvote 0
It can be either. Currently the data is in two workbooks. They can easily be combined into two worksheets within a single workbook.

Thank!
Steve
 
Upvote 0
symphonic,

Lets work with one workbook, containing the two worksheets of raw data, and a Result worksheet.

Can we have a screenshot of each of the two worksheets that contain the raw data, in the exact format that each has (with no additional/blank columns).

And, can we have a screenshot of the Result worksheet in the format you are looking for (titles in the correct column location).
 
Upvote 0
Thanks, Hiker95.
Below you will see three screenshots. The first shows the data of one worksheet (with Business type), the second shows the data of the second worksheet (with Contact ID), and the third shows the combined data.

Just so I'm prefectly clear, the complete spreadsheet has 32,000 contacts (rows). The two spreadsheets are not exact matches in that one has more rows (contacts) on it than the other--so a simple sort, and then copy/paste won't do the job.

Thanks,
Steve
Excel Workbook
ABCDE
1First NameLast NameTitleAccount NameBusiness Type
2LawrenceAaronsonPARTNERMcDonnell Boehnen Hulbert & BerghoffLaw Firm, Private Attorneys
3RachelAaronsonASSOCIATEMcDermott Will & EmeryPrivate Attorneys
4EricAarrestadWatchGuardTechnology
5JesseAbairASSOCIATERackemann, Sawyer & BrewsterPrivate Attorneys
6StephenAbarbanelCOUNSELRobinson & ColePrivate Attorneys
7FredAbaroaCMOCosta Vida Fresh Mexican GrillFood & Beverage
8RichardAbatiPARTNERChoate Hall & Stewart LLPLaw Firm, Private Attorneys
9JafferAbbasiASSOCIATEHunton & WilliamsPrivate Attorneys
10GailAbbeyASSOCIATEEdwards Angell Palmer & DodgePrivate Attorneys
Incl Bus. Type
Excel 2010
Excel Workbook
ABCDE
1First NameLast NameTitleAccount NameContact ID
2LawrenceAaronsonPARTNERMcDonnell Boehnen Hulbert & Berghoff0038000000Z3qFU
3EricAarrestadWatchGuard0038000000fnLIa
4JesseAbairASSOCIATERackemann, Sawyer & Brewster0038000000Z3tlW
5StephenAbarbanelCOUNSELRobinson & Cole0038000000Z3tm1
6FredAbaroaCMOCosta Vida Fresh Mexican Grill0038000000Z3iS6
7RichardAbatiPARTNERChoate Hall & Stewart LLP0038000000Z3tSt
8JafferAbbasiASSOCIATEHunton & Williams0038000000Z3uML
9GailAbbeyASSOCIATEEdwards Angell Palmer & Dodge0038000000Z3tVV
10TonyAbbinanteDirector Trade & Community RelationsDiageo0038000000t03lk
Incl ID
Excel 2010
Excel Workbook
ABCDEF
1First NameLast NameTitleAccount NameBusiness TypeContact ID
2LawrenceAaronsonPARTNERMcDonnell Boehnen Hulbert & BerghoffLaw Firm, Private Attorneys0038000000Z3qFU
3EricAarrestadWatchGuardTechnology0038000000fnLIa
4JesseAbairASSOCIATERackemann, Sawyer & BrewsterPrivate Attorneys0038000000Z3tlW
5StephenAbarbanelCOUNSELRobinson & ColePrivate Attorneys0038000000Z3tm1
6FredAbaroaCMOCosta Vida Fresh Mexican GrillFood & Beverage0038000000Z3iS6
7RichardAbatiPARTNERChoate Hall & Stewart LLPLaw Firm, Private Attorneys0038000000Z3tSt
8JafferAbbasiASSOCIATEHunton & WilliamsPrivate Attorneys0038000000Z3uML
9GailAbbeyASSOCIATEEdwards Angell Palmer & DodgePrivate Attorneys0038000000Z3tVV
10TonyAbbinanteDirector Trade & Community RelationsDiageo0038000000t03lk
Complete
Excel 2010
 
Upvote 0
symphonic,

Sorry for the delay. I was trying to solve your request with arrays. If I can come up with a solution with arrays, I will post the results.


Sample worksheets in one workbook:


Excel Workbook
ABCDE
1First NameLast NameTitleAccount NameBusiness Type
2LawrenceAaronsonPARTNERMcDonnell Boehnen Hulbert & BerghoffLaw Firm, Private Attorneys
3RachelAaronsonASSOCIATEMcDermott Will & EmeryPrivate Attorneys
4EricAarrestadWatchGuardTechnology
5JesseAbairASSOCIATERackemann, Sawyer & BrewsterPrivate Attorneys
6StephenAbarbanelCOUNSELRobinson & ColePrivate Attorneys
7FredAbaroaCMOCosta Vida Fresh Mexican GrillFood & Beverage
8RichardAbatiPARTNERChoate Hall & Stewart LLPLaw Firm, Private Attorneys
9JafferAbbasiASSOCIATEHunton & WilliamsPrivate Attorneys
10GailAbbeyASSOCIATEEdwards Angell Palmer & DodgePrivate Attorneys
11
Incl Bus. Type





Excel Workbook
ABCDE
1First NameLast NameTitleAccount NameContact ID
2LawrenceAaronsonPARTNERMcDonnell Boehnen Hulbert & Berghoff0038000000Z3qFU
3EricAarrestadWatchGuard0038000000fnLIa
4JesseAbairASSOCIATERackemann, Sawyer & Brewster0038000000Z3tlW
5StephenAbarbanelCOUNSELRobinson & Cole0038000000Z3tm1
6FredAbaroaCMOCosta Vida Fresh Mexican Grill0038000000Z3iS6
7RichardAbatiPARTNERChoate Hall & Stewart LLP0038000000Z3tSt
8JafferAbbasiASSOCIATEHunton & Williams0038000000Z3uML
9GailAbbeyASSOCIATEEdwards Angell Palmer & Dodge0038000000Z3tVV
10TonyAbbinanteDirector Trade & Community RelationsDiageo0038000000t03lk
11
Incl ID





After the macro in a new worksheet Complete:


Excel Workbook
ABCDEF
1First NameLast NameTitleAccount NameBusiness TypeContact ID
2LawrenceAaronsonPARTNERMcDonnell Boehnen Hulbert & BerghoffLaw Firm, Private Attorneys0038000000Z3qFU
3RachelAaronsonASSOCIATEMcDermott Will & EmeryPrivate Attorneys
4EricAarrestadWatchGuardTechnology0038000000fnLIa
5JesseAbairASSOCIATERackemann, Sawyer & BrewsterPrivate Attorneys0038000000Z3tlW
6StephenAbarbanelCOUNSELRobinson & ColePrivate Attorneys0038000000Z3tm1
7FredAbaroaCMOCosta Vida Fresh Mexican GrillFood & Beverage0038000000Z3iS6
8RichardAbatiPARTNERChoate Hall & Stewart LLPLaw Firm, Private Attorneys0038000000Z3tSt
9JafferAbbasiASSOCIATEHunton & WilliamsPrivate Attorneys0038000000Z3uML
10GailAbbeyASSOCIATEEdwards Angell Palmer & DodgePrivate Attorneys0038000000Z3tVV
11TonyAbbinanteDirector Trade & Community RelationsDiageo0038000000t03lk
12
Complete





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, by highlighting the code and pressing the keys CTRL + C
2. Open your 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 by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub ComineTwo()
' hiker95, 06/28/2011
' http://www.mrexcel.com/forum/showthread.php?t=559828
Dim wB As Worksheet, wI As Worksheet, wC As Worksheet
Dim LR As Long, a As Long, aa As Long, NR As Long, r As Long
Application.ScreenUpdating = False
Set wB = Worksheets("Incl Bus. Type")
Set wI = Worksheets("Incl ID")
If Not Evaluate("ISREF(Complete!A1)") Then Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Complete"
Set wC = Worksheets("Complete")
wC.UsedRange.Clear
wC.Range("A1:B1") = [{"First Name","Last Name"}]
LR = wB.Cells(Rows.Count, 1).End(xlUp).Row
With wB.Range("F2:F" & LR)
  .FormulaR1C1 = "=RC[-5]&RC[-4]"
  .Value = .Value
End With
NR = wC.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
wB.Range("A2:B" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wC.Range("A" & NR), Unique:=True
LR = wI.Cells(Rows.Count, 1).End(xlUp).Row
With wI.Range("F2:F" & LR)
  .FormulaR1C1 = "=RC[-5]&RC[-4]"
  .Value = .Value
End With
NR = wC.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
wI.Range("A2:B" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wC.Range("A" & NR), Unique:=True
LR = wC.Cells(Rows.Count, 1).End(xlUp).Row
wC.Range("A2:B" & LR).Sort Key1:=wC.Range("B2"), Order1:=xlAscending, Key2:=wC.Range("A2") _
  , Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
  Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
wC.Columns("A:B").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wC.Range("C1"), Unique:=True
wC.Columns("A:B").Delete
With wC.Range("A1:F1")
  .Value = [{"First Name","Last Name","Title","Account Name","Business Type","Contact ID"}]
  .HorizontalAlignment = xlCenter
  .Font.FontStyle = "Bold"
End With
LR = wC.Cells(Rows.Count, 1).End(xlUp).Row
With wC.Range("G2:G" & LR)
  .FormulaR1C1 = "=RC[-6]&RC[-5]"
  .Value = .Value
End With
For a = 2 To LR Step 1
  r = 0
  On Error Resume Next
  r = Application.Match(wC.Cells(a, 7), wB.Columns(6), 0)
  On Error GoTo 0
  If r > 0 Then
    For aa = 3 To 5
      If wB.Cells(r, aa) <> "" Then wC.Cells(a, aa) = wB.Cells(r, aa)
    Next aa
  End If
  r = 0
  On Error Resume Next
  r = Application.Match(wC.Cells(a, 7), wI.Columns(6), 0)
  On Error GoTo 0
  If r > 0 Then
    For aa = 3 To 4
      If wI.Cells(r, aa) <> "" Then wC.Cells(a, aa) = wI.Cells(r, aa)
    Next aa
    If wI.Cells(r, 5) <> "" Then wC.Cells(a, 6) = wI.Cells(r, 5)
  End If
Next a
wB.Columns(6).Clear
wI.Columns(6).Clear
wC.Columns(7).Clear
wC.UsedRange.Columns.AutoFit
wC.Activate
Application.ScreenUpdating = True
End Sub


Then run the ComineTwo macro.
 
Upvote 0
symphonic,


Same screenshots as my Reply #8, with all worksheets in the same workbook, but this latest macro is uisng arrays, and should be faster.



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, by highlighting the code and pressing the keys CTRL + C
2. Open your 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 by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Option Base 1
Sub CombineTwo()
' hiker95, 06/28/2011
' http://www.mrexcel.com/forum/showthread.php?t=559828
Dim wB As Worksheet, wI As Worksheet, wC As Worksheet
Dim B() As Variant, I() As Variant, C() As Variant, BB() As Variant, II() As Variant
Dim LR As Long, a As Long, aa As Long, NR As Long, r As Long
Application.ScreenUpdating = False
Set wB = Worksheets("Incl Bus. Type")
Set wI = Worksheets("Incl ID")
If Not Evaluate("ISREF(Complete!A1)") Then Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Complete"
Set wC = Worksheets("Complete")
wC.UsedRange.Clear
wC.Range("A1:B1") = [{"First Name","Last Name"}]
LR = wB.Cells(Rows.Count, 1).End(xlUp).Row
With wB.Range("F2:F" & LR)
  .FormulaR1C1 = "=RC[-5]&RC[-4]"
  .Value = .Value
End With
NR = wC.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
wB.Range("A2:B" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wC.Range("A" & NR), Unique:=True
LR = wI.Cells(Rows.Count, 1).End(xlUp).Row
With wI.Range("F2:F" & LR)
  .FormulaR1C1 = "=RC[-5]&RC[-4]"
  .Value = .Value
End With
NR = wC.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
wI.Range("A2:B" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wC.Range("A" & NR), Unique:=True
LR = wC.Cells(Rows.Count, 1).End(xlUp).Row
wC.Range("A2:B" & LR).Sort Key1:=wC.Range("B2"), Order1:=xlAscending, Key2:=wC.Range("A2") _
  , Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
  Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
wC.Columns("A:B").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wC.Range("C1"), Unique:=True
wC.Columns("A:B").Delete
With wC.Range("A1:F1")
  .Value = [{"First Name","Last Name","Title","Account Name","Business Type","Contact ID"}]
  .HorizontalAlignment = xlCenter
  .Font.FontStyle = "Bold"
End With
LR = wC.Cells(Rows.Count, 1).End(xlUp).Row
With wC.Range("G2:G" & LR)
  .FormulaR1C1 = "=RC[-6]&RC[-5]"
  .Value = .Value
End With
LR = wB.Cells(Rows.Count, 1).End(xlUp).Row
B = wB.Range("A1:F" & LR).Value
BB = wB.Range("F1:F" & LR).Value
wB.Columns(6).Clear
LR = wI.Cells(Rows.Count, 1).End(xlUp).Row
I = wI.Range("A1:F" & LR).Value
II = wI.Range("F1:F" & LR).Value
wI.Columns(6).Clear
LR = wC.Cells(Rows.Count, 1).End(xlUp).Row
C = wC.Range("A1:G" & LR).Value
For a = LBound(C) + 1 To UBound(C)
  r = 0
  On Error Resume Next
  r = Application.Match(C(a, 7), BB, 0)
  On Error GoTo 0
  If r > 0 Then
    For aa = 3 To 5
      If B(r, aa) <> "" Then C(a, aa) = B(r, aa)
    Next aa
  End If
  r = 0
  On Error Resume Next
  r = Application.Match(C(a, 7), II, 0)
  On Error GoTo 0
  If r > 0 Then
    For aa = 3 To 4
      If I(r, aa) <> "" Then C(a, aa) = I(r, aa)
    Next aa
    If I(r, 5) <> "" Then C(a, 6) = I(r, 5)
  End If
Next a
wC.Range("A1:G" & LR).Value = C
wC.Columns(7).Clear
wC.UsedRange.Columns.AutoFit
Erase B: Erase I: Erase C: Erase BB: Erase II
wC.Activate
Application.ScreenUpdating = True
End Sub


Then run the CombineTwo macro.
 
Last edited:
Upvote 0
Thanks, Hiker95. Really appreciate you trying to help me out!!

I've followed your instructions. When I run the code, I get Run-time error '9': Subsrcipt out of range dialog box. When I click debug on the dialog box, it highlights the following from the macro code:

Set wB = Worksheets("Incl Bus. Type")

I tried the code on a copy of the full data set, then tried it on a much smaller set. Both times I got the same error.

Best to you for the holiday weekend!
Steve
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,626
Members
452,933
Latest member
patv

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