Combine 2 columns using VBA

U

ub

Hi
I have data in approx 800 lines as:Column A Column B
Cook Mark
Jones Peter

Column A has last name, Column B has first name.
I want to joing data of 2 columns to show Firstname Lastname in ColumnA and
then delete Column B

Please advise how to write this code
 
D

Don Guillett

For each c in range("a2"a800")
c.value= c & " " & c.offset(,1)
next c
columns(2).delete
 
R

Robert Flanagan

You can do without code. Use the formula

=A1 & " " & B1

in column C and copy down. Then copy the formula cells and do an edit,
paste special values back over the formulas. Then delete columns A and B

Robert Flanagan
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel
 
M

Mike H

Hi,

Right click your sheet tab, view code and paste this in and run it.

Sub sonic()
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
c.Value = c.Offset(, 1).Value & " " & c.Value
Next
Columns(2).ClearContents
End Sub

Mike
 
U

ub

Thanks , it works


Mike H said:
Hi,

Right click your sheet tab, view code and paste this in and run it.

Sub sonic()
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
c.Value = c.Offset(, 1).Value & " " & c.Value
Next
Columns(2).ClearContents
End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top