ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro to Combine 2 columns to make one column without merging (https://www.excelbanter.com/excel-discussion-misc-queries/62592-macro-combine-2-columns-make-one-column-without-merging.html)

JRM

Macro to Combine 2 columns to make one column without merging
 
I found this macro courtesy of Dave:

Option Explicit
Sub testme02()

Dim myRng As Range
Dim myArea As Range
Dim myRow As Range
Dim myCell As Range
Dim myStr As String

Set myRng = Selection

Application.DisplayAlerts = False
For Each myArea In myRng.Areas
If myArea.Columns.Count 1 Then
For Each myRow In myArea.Rows
myStr = ""
For Each myCell In myRow.Cells
myStr = myStr & " " & myCell.Text
Next myCell
myRow.Merge across:=True
myRow.Cells(1).Value = Mid(myStr, 2)
Next myRow
End If
Next myArea
Application.DisplayAlerts = True

End Sub

And it does a good job of merging but I need to just cut the data in the
right column and splice it onto the end of the data in the left column. That
way when I'm finished the right column can be deleted. If I merge then the
right column can't be deleted and it ruins my export to CSV files.

Thanks for your help!

Richard
--
When we die, we leave all that we have... and take with us all that we are.
Ravi Zacharias

Don Guillett

Macro to Combine 2 columns to make one column without merging
 
see if this helps
Sub putcolumnstogether()
x = Cells(Rows.Count, "h").End(xlUp).Row
For Each c In Range(Cells(2, "h"), Cells(x, "h"))
c.Value = c & " " & c.Offset(, 1)
Next
Columns("i").Delete
End Sub

--
Don Guillett
SalesAid Software

"JRM" wrote in message
...
I found this macro courtesy of Dave:

Option Explicit
Sub testme02()

Dim myRng As Range
Dim myArea As Range
Dim myRow As Range
Dim myCell As Range
Dim myStr As String

Set myRng = Selection

Application.DisplayAlerts = False
For Each myArea In myRng.Areas
If myArea.Columns.Count 1 Then
For Each myRow In myArea.Rows
myStr = ""
For Each myCell In myRow.Cells
myStr = myStr & " " & myCell.Text
Next myCell
myRow.Merge across:=True
myRow.Cells(1).Value = Mid(myStr, 2)
Next myRow
End If
Next myArea
Application.DisplayAlerts = True

End Sub

And it does a good job of merging but I need to just cut the data in the
right column and splice it onto the end of the data in the left column.
That
way when I'm finished the right column can be deleted. If I merge then
the
right column can't be deleted and it ruins my export to CSV files.

Thanks for your help!

Richard
--
When we die, we leave all that we have... and take with us all that we
are.
Ravi Zacharias





All times are GMT +1. The time now is 04:40 AM.

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