ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Combining colums in Excel (https://www.excelbanter.com/excel-programming/424576-combining-colums-excel.html)

Varun

Combining colums in Excel
 
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.

Rick Rothstein

Combining colums in Excel
 
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.

--
Rick (MVP - Excel)


"Varun" wrote in message
...
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.




All times are GMT +1. The time now is 08:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com