Using Macro To Merge Two Columns

  • Thread starter Thread starter Josh in Tampa
  • Start date Start date
J

Josh in Tampa

hello. here's the situation i need a little help with.

i have two columns.....A and B.

both columns hold email addresses. if there is an email
address for a particular record in column A then there is
no email address in column B, and vice versa.

i would like to create a macro that will merge the two.
how can i do this? thank you very much.
 
Josh,

This will replace column A with the addresses [watch for word wrap]
Change the 1 in Cells(x, 1) to whatever if you want it in a different
column.

Dim lrow As Long, x As Long

' determine number of rows
lrow = WorksheetFunction.Max(Cells(Rows.Count, "A").End(xlUp).Row, _
Cells(Rows.Count, "B").End(xlUp).Row)

' loop and replace
For x = 1 To lrow
Cells(x, 1) = Cells(x, 1) & Cells(x, 2)
Next
 
Dim rng as Range
Dim cell as Range
On Error Resume Next
set rng = Columns(1).SpecialCells(xlBlanks)
On Error goto 0
if not rng is nothing then
for each cell in rng
cell.Value = cell.Offset(0,1).Value
cell.Offset(0,1).ClearContents
Next
End If
 
Back
Top