PC Review


Reply
Thread Tools Rate Thread

Combine 2 columns using VBA

 
 
ub
Guest
Posts: n/a
 
      21st Oct 2009
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
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      21st Oct 2009
For each c in range("a2"a800")
c.value= c & " " & c.offset(,1)
next c
columns(2).delete

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"ub" <(E-Mail Removed)> wrote in message
news:380E72FA-255B-4DD7-9F12-(E-Mail Removed)...
> 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


 
Reply With Quote
 
Robert Flanagan
Guest
Posts: n/a
 
      21st Oct 2009
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

"ub" <(E-Mail Removed)> wrote in message
news:380E72FA-255B-4DD7-9F12-(E-Mail Removed)...
> 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



 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      21st Oct 2009
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

"ub" wrote:

> 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

 
Reply With Quote
 
ub
Guest
Posts: n/a
 
      21st Oct 2009
Thanks , it works


"Mike H" wrote:

> 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
>
> "ub" wrote:
>
> > 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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: combine columns Mike H Microsoft Excel Misc 0 23rd Sep 2008 02:07 PM
Combine multiple columns into two long columns, Repeating rows in first column anasab@gmail.com Microsoft Excel Misc 2 31st Jul 2006 09:45 PM
Combine multiple columns into two long columns, Repeating rows in first column anasab@gmail.com Microsoft Excel Misc 0 31st Jul 2006 05:07 PM
combine columns tombates@city-net.com Microsoft Excel Programming 14 11th Jan 2006 07:10 PM
How to combine two columns? =?Utf-8?B?Um9iZXJ0IEp1ZGdl?= Microsoft Excel Worksheet Functions 1 23rd May 2005 06:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:23 PM.