There are a couple of ways to do this, I think the easiest is to use a macro
to get the job done. The code below will do it once you make the changes to
the Const values set up at the beginning to go along with the way your
worksheet is set up now. As always, test on a copy of the sheet to begin
with so you don't lose any original information. This is a destructive
process (the .Delete portion), so if one of us doesn't get it right, data
loss is very possible. Just make a copy of your .xls file to try it out in,
that way the original stays in one piece.
To put the code in a module so you can get to it with Tools | Macro |
Macros, open the (copy) workbook and press [Alt]+[F11] to get into the
VB
Editor, choose Insert | Module from the
VB Editor menu and cut and paste the
code below into that and then close the
VB Editor. Choose the sheet with the
information on it and run the macro.
Sub MovePhoneNumbers()
'change these constants to match with
'layout of your sheet
Const ColumnWithNames = "A"
Const oldPhoneColumn = "B" ' move from
Const newPhoneColumn = "C" ' move to
Const firstRowWithAName = 1 ' 2 if you have title/header in row 1
Dim LastRowWithAName As Long
Dim rowNumber As Long
If Val(Left(Application.Version, 2)) < 12 Then
'in pre-2007 Excel
LastRowWithAName = _
Range(ColumnWithNames & Rows.Count).End(xlUp).Row
Else
'in Excel 2007 (or later)
LastRowWithAName = _
Range(ColumnWithNames & Rows.CountLarge).End(xlUp).Row
End If
'this presumes things are as you described:
'two rows per person, 1st row has address info
'2nd row has phone # that needs to be moved and then deleted
For rowNumber = firstRowWithAName To LastRowWithAName Step 2
'do the copy
Range(newPhoneColumn & rowNumber) = _
Range(oldPhoneColumn & rowNumber + 1)
Range(oldPhoneColumn & rowNumber + 1).EntireRow.Delete
rowNumber = rowNumber - 1 ' adjust for deleted row!
Next
End Sub
"crcurrie" wrote:
I have a spreadsheet with records of persons with their address and other
information and records of the same persons with their phone numbers. The
rows are sorted by name so that the row with address and the row with phone
number are adjacent. What I need to do is merge the phone number onto the
row with the address and other data and then delete the row with the name and
phone number. Is there a way to do that in Excel? -- Chris