View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Macro/SUB to merge two columns of text

Columns(ac).Resize(, 2).Replace " ", ""

I'm not sure you want to "trim" the spaces using the above line... what if one (or more) of the cells contained text with multiple words separated by spaces?

--
Rick (MVP - Excel)


"Don Guillett" wrote in message ...
Sub maketwocolumnsone()
ac = ActiveCell.Column
'line below trims spaces
Columns(ac).Resize(, 2).Replace " ", ""

lr = Cells(Rows.Count, ac).End(xlUp).Row
For i = 2 To lr
Cells(i, ac).Value = Cells(i, ac) & " " & Cells(i, ac + 1)
Next i
Columns(ac + 1).Delete
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Hershmab" wrote in message
...
EXCEL 2003: How do I write a VBA subroutine to:
(1) Take each cell in the currently-SELECTED column
(2) Append to its (text) contents the text in the corresponding cell of
the NEXT column
(3) Replace the result in the original cell
(4) On completion, delete the whole of the NEXT column?
All text values need to have leading and trailing blanks TRIMMED before
being concatenated.

This is to cope with the situation where downloaded data contains
information split over two columns that the worksheet needs to have in
one,
e.g. company name and branch location.