Sorry, lost track of time! The code below should do the trick for you, copy
it into your workbook and change any of the Const values as required for the
setup in your workbook. You can then run the macro to get the job done.
To put the code into your workbook: start by making a copy of your
workbook, just in case. Then open the copy, Press [Alt]+[F11] to enter the
VB Editor. Use Insert --> Module to create a new code module and then copy
the code below and paste it into that code module. Make any changes to the
constants that you need to. Close the VB Editor, save the workbook and run
the macro to get the job done, either from Tools --> Macro --> Macros in
Excel 2003 & earlier, or from the Developer's tab in Excel 2007.
Sub CopyPhoneNumbers()
'copies data (phone numbers) from a
'specific column of Sheet2 to a specific
'column of Sheet1 when the name (or other data)
'in two more specified columns matches on both
'sheets
'
'Information about the sheet where we copy TO
'i.e., the destination sheet
Const destSheetName = "Sheet1"
Const destNameColumn = "A"
Const destPhoneColumn = "E"
'
'information about the sheet that we copy FROM
'i.e., the source sheet
Const sourceSheetName = "Sheet2"
Const sourceNameColumn = "A"
Const sourcePhoneColumn = "D"
'
'general variables to get the work done
'
Dim destWS As Worksheet
Dim destNamesList As Range
Dim anyDestName As Range
Dim srcWS As Worksheet
Dim srcNamesList As Range
Dim anySrcName As Range
'begin the work
Set destWS = ThisWorkbook.Worksheets(destSheetName)
'assumes data starts on row 2
Set destNamesList = destWS.Range(destNameColumn & _
"2:" & destWS.Range(destNameColumn & Rows.Count). _
End(xlUp).Address)
Set srcWS = ThisWorkbook.Worksheets(sourceSheetName)
'assumes data starts on row 2
Set srcNamesList = srcWS.Range(sourceNameColumn & _
"2:" & srcWS.Range(sourceNameColumn & Rows.Count). _
End(xlUp).Address)
' improve performance
Application.ScreenUpdating = False
'compare and copy as appropriate
'this does EXACT matches of names
For Each anySrcName In srcNamesList
For Each anyDestName In destNamesList
If anySrcName = anyDestName Then
destWS.Range(destPhoneColumn & _
anyDestName.Row) = _
srcWS.Range(sourcePhoneColumn & _
anySrcName.Row)
End If
Next
Next
'cleanup and housekeeping
Set srcNamesList = Nothing
Set srcWS = Nothing
Set destNamesList = Nothing
Set destWS = Nothing
MsgBox "Task has completed."
End Sub
Benjamin said:
No doubt it is possible, but the question becomes how to get it done.
At a very simple level you could copy the column and then use
Edit --> Paste Special with the "Transpose" option selected to 'rotate' the
column into a single row. But somehow I think there's more to it than this.
What defines a "common column"? Do you have row headings in column A on the
first sheet that could be matched to column headings on the other sheet? Like
First Sheet Second Sheet
A B A B
C
1 Name joe 1 Name Addr City
2 Addr 101 main st. 2 joe 101 M... NYC
3 City NYC
4 Name ....
or is your data in the first sheet simply grouped into separate constant
number of rows (as above perhaps groups of 3 rows [name, addr, city]) or more?
I have a column in one spreadsheet that I would like to copy into
another spreadsheet, rearranging the rows to match up with a common
column.
Ben
.- Hide quoted text -
Hopefully this clarifies:
Currently,
First Sheet Second Sheet
1 Name DOB ID# Job 1 Name Addr City Phone
2 Abe 2 Ben
3 Ben 3 Carla
4 Carla 4 Abe
I'd like to copy the Phone column from the second sheet to the first
sheet. Problem is that the name lists only contain some of the same
entries and some phone #'s are blank.
Thanks!- Hide quoted text -
- Show quoted text -
Formatting got messed up for some reason, hopefully this works:
Currently,
First Sheet Second Sheet
1 Name DOB ID# Job 1 Name Addr City Phone
2 Abe 2 Ben
3 Ben 3 Carla
4 Carla 4 Abe
I'd like to copy the Phone column from the second sheet to the first
sheet. Problem is that the name lists only contain some of the same
entries and some phone #'s are blank.
.