Macro for Creating New Columns and Transferring Text

macrocodehelp1

New Member
Joined
Jul 6, 2018
Messages
1
Hello!

I'm trying to write a macro to create five new columns (after column F), give the headers specific names, and transfer text after line breaks from column F.

For example, a cell in column F may read:

John Smith
Jane Doe
George Parker
Michael Scott

I would want John Smith to remain in the cell, Jane Doe (after the line break) to move to the next, newly created column, George Parker to move to the new column after Jane Doe, etc.

Also, less important: is it possible to have a specific name always go to a specified column? So, for example, could I have Jane Doe automatically move to the third new column, even if she's the second name in the cell?

Thank you in advance!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
How about
Code:
Sub SplitData()
   Dim Cl As Range
   Range("G1:K1").Value = Array("G", "H", "I", "J", "K")
   For Each Cl In Range("F2", Range("F" & Rows.Count).End(xlUp))
      Cl.Resize(, 6).Value = Split(Cl, Chr(10))
   Next Cl
   Range("G:K").SpecialCells(xlConstants, xlErrors).ClearContents
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top