Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combine Two Worksheets
I have two files with the following columns:
FILE 1 FILE 2 A: User ID A: End User B: First Name B: Name C: Last Name C: SSN D: Active User E: Payment F: Payment Total G: Last Payment Date The common field is Column A in both tables. I want to start with File 2 and bring the contents of Column E in File 1 into File 2. My new file would then be: A: End User B: Name C: SSN D: Payment (field inserted from File 1) Thanks in advance for any help with this. -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200905/1 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combine Two Worksheets
Hi
Insert the code in "File2", and change file / sheet names as required. Sub Combine() Dim wbA As Workbook Dim wbB As Workbook Dim shA As Worksheet Dim shB As Worksheet Set wbA = ThisWorkbook Set wbB = Workbooks("File1.xls") 'Change name to suit Set shA = wbA.Worksheets("Sheet1") Set shB = wbB.Worksheets("Sheet1") LastRow = shA.Range("A1").End(xlDown).Row For r = 2 To LastRow ' Headings in row 1 EndUser = Cells(r, 1).Value Set f = shB.Columns("A").Find(what:=EndUser, LookAt:=xlWhole) If Not f Is Nothing Then shA.Cells(r, 4) = shB.Cells(f.Row, 5).Value Set f = Nothing End If Next End Sub Regards, Per On 8 Maj, 15:11, "Evan_Robitaille via OfficeKB.com" <u28944@uwe wrote: I have two files with the following columns: FILE 1 * * * * * * * * * * * * * * * * * * * FILE 2 A: User ID * * * * * * * * * * * * * * * *A: End User B: First Name * * * * * * * * * * * * * B: Name C: Last Name * * * * * * * * * * * * * C: SSN D: Active User E: Payment F: Payment Total G: Last Payment Date The common field is Column A in both tables. *I want to start with File 2 and bring the contents of Column E in File 1 into File 2. *My new file would then be: A: End User B: Name C: SSN D: Payment (field inserted from File 1) Thanks in advance for any help with this. -- Message posted via OfficeKB.comhttp://www.officekb.com/Uwe/Forums.aspx/excel-programming/200905/1 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combine Two Worksheets
Thanks for your help with this, worked like a charm.
Per Jessen wrote: Hi Insert the code in "File2", and change file / sheet names as required. Sub Combine() Dim wbA As Workbook Dim wbB As Workbook Dim shA As Worksheet Dim shB As Worksheet Set wbA = ThisWorkbook Set wbB = Workbooks("File1.xls") 'Change name to suit Set shA = wbA.Worksheets("Sheet1") Set shB = wbB.Worksheets("Sheet1") LastRow = shA.Range("A1").End(xlDown).Row For r = 2 To LastRow ' Headings in row 1 EndUser = Cells(r, 1).Value Set f = shB.Columns("A").Find(what:=EndUser, LookAt:=xlWhole) If Not f Is Nothing Then shA.Cells(r, 4) = shB.Cells(f.Row, 5).Value Set f = Nothing End If Next End Sub Regards, Per On 8 Maj, 15:11, "Evan_Robitaille via OfficeKB.com" <u28944@uwe wrote: I have two files with the following columns: [quoted text clipped - 19 lines] -- Message posted via OfficeKB.comhttp://www.officekb.com/Uwe/Forums.aspx/excel-programming/200905/1 -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200905/1 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Combine 3 of 6 worksheets | Excel Discussion (Misc queries) | |||
How do I combine worksheets w/o enough rows to combine? | Excel Worksheet Functions | |||
Combine Worksheets | Excel Worksheet Functions | |||
How to combine several worksheets | Setting up and Configuration of Excel | |||
Combine All Worksheets into one | Excel Programming |