Combining colums in Excel

V

Varun

Hi,

I'd like to know how to take the text from cells in column B and "append" it
to the text contained in column A. For example, here's what I have:

Col A Col B
good bad
boy girl
uncle aunt

I'd like to modified Col A as below:

Col A
goodbad
boygirl
uncleaunt

How can I do this? I tried to do this by writing the code below but that
doesn't work since it's recursive.

Worksheets("Temp3").Cells(startrow1, 4).Value =
Worksheets("Temp3").Cells(startrow1, 4).Value & _
Worksheets("Temp3").Cells(startrow1, 4).Value & ","

Thanks for help.
 
R

Rick Rothstein

Give this macro a try...

Sub CombineAandB()
Dim X As Long
Dim LastRow As Long
Const StartRow As Long = 2
With Worksheets("sheet 3")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For X = StartRow To LastRow
.Cells(X, "A").Value = .Cells(X, "A").Value & .Cells(X, "B").Value
Next
' Comment the following line out if you don't
' want to delete the contents of Column B
.Range("B" & StartRow & ":B" & LastRow).Clear
End With
End Sub

And note the commented line inside the code.
 
Top