How to split multiple data into separate columns using macro? Help please...

princess0703

New Member
Joined
Apr 12, 2011
Messages
22
How to split multiple data into separate columns using macro? Help please...Thank you very much :)

ex. in a single cell there are name 1 : queen star, name 2 : cess kabahar, name 3 :leah moshie, website : a@b.com, phone number : 123456 and i want to remove name 1 :, name 2, name 3 :, website :, phone number : but i want to retain the specific names. thanks a lot. any ideas how to do that using excel macros?
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Welcome to MrExcel board....

using your example here is a macro, be sure to make a copy of your sheet before trying this.

Code:
Sub ParseData()
Dim LR As Long
LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
SC = ActiveCell.Row
' parse out HR file says data
For i = LR To SC Step -1

    MCC = Application.WorksheetFunction.Find("|", Application.WorksheetFunction.Substitute(Cells(i, 1).Value, ":", "|", 5)) + 2
    MCC1 = Application.WorksheetFunction.Find("|", Application.WorksheetFunction.Substitute(Cells(i, 1).Value, ":", "|", 4)) + 2
    MCC2 = Application.WorksheetFunction.Find("|", Application.WorksheetFunction.Substitute(Cells(i, 1).Value, ":", "|", 3)) + 2
    MCC3 = Application.WorksheetFunction.Find("|", Application.WorksheetFunction.Substitute(Cells(i, 1).Value, ":", "|", 2)) + 2
    MCC4 = Application.WorksheetFunction.Find("|", Application.WorksheetFunction.Substitute(Cells(i, 1).Value, ":", "|", 1)) + 2
    Cells(i, 5) = Mid(Cells(i, 1), MCC, Len(Cells(i, 1)) - MCC + 1)
    Cells(i, 4) = Mid(Cells(i, 1), MCC1, MCC - 17 - MCC1)
    Cells(i, 3) = Mid(Cells(i, 1), MCC2, MCC1 - 12 - MCC2)
    Cells(i, 2) = Mid(Cells(i, 1), MCC3, MCC2 - 11 - MCC3)
    Cells(i, 1) = Mid(Cells(i, 1), MCC4, MCC3 - 11 - MCC4)
Next i
MsgBox "Done"
Application.ScreenUpdating = True
End Sub
 
Upvote 0
<table border="0" cellpadding="0" cellspacing="0" width="498"><colgroup><col width="498"></colgroup><tbody><tr height="171"> <td class="xl63" style="height:128.25pt;width:374pt" height="171" width="498">here is ex. the data in one cell :
Contact Person 1 : cess1 (Core Founder)
Contact Person 2 : cess2 (President)
Contact Person 3 : cess3 (Vice President)
Contact Number : 555 555 111111
Revenue : 1,000,000 (2009)
Number of Employees : 45
Number of Global Offices : 3
Website : a.c.com


HOW IT IS REQUIRED :
CONTACTS POSITION PHONE NUMBER # OF EMPLOYEES WEBsite
Cess 1 Core founder
555 555 111111 45 www. cess.com
Cess 2 President
Cess 3 Vice President


do you have any ideas how to do this in macro? thank you so much..;)
</td> </tr></tbody></table>
 
Last edited:
Upvote 0
<table style="width: 779px; height: 194px;" border="0" cellpadding="0" cellspacing="0"><colgroup><col width="498"></colgroup><tbody><tr height="171"> <td class="xl63" style="height: 128.25pt; width: 374pt;" height="171" width="498">here is ex. the data in one cell :
Contact1 : cess1 (Core Founder)
Nicknme# : che
Number : 123456
Fave color : red
Fave song: She
Website : a.c.com


HOW IT IS REQUIRED (the output should be like this:
CONTACTS POSITION NICKNME CONTACT # FAVE COLOR FAVE SONG WEBSITE
Cess 1 founder che
123456 red She a.c.com

</td> </tr></tbody></table>

Text removed by Moderator
 
Last edited by a moderator:
Upvote 0
so using the modified criteria try this

Code:
Sub ParseData()
Dim LR As Long
Application.ScreenUpdating = False
' parse out HR file says data
        Rows(1).EntireRow.Insert
LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
SC = ActiveCell.Offset(1, 0).Row
Cells(1, 8) = "Website"
Cells(1, 7) = "FAVE SONG"
Cells(1, 6) = "FAVE COLOR"
Cells(1, 5) = "CONTACT"
Cells(1, 4) = "NICKNME"
Cells(1, 3) = "POSITION"
Cells(1, 2) = "CONTACTS"
For i = LR To SC Step -1
    MCC = Application.WorksheetFunction.Find("|", Application.WorksheetFunction.Substitute(Cells(i, 1).Value, ":", "|", 6)) + 2
    MCC1 = Application.WorksheetFunction.Find("|", Application.WorksheetFunction.Substitute(Cells(i, 1).Value, ":", "|", 5)) + 2
    MCC2 = Application.WorksheetFunction.Find("|", Application.WorksheetFunction.Substitute(Cells(i, 1).Value, ":", "|", 4)) + 2
    MCC3 = Application.WorksheetFunction.Find("|", Application.WorksheetFunction.Substitute(Cells(i, 1).Value, ":", "|", 3)) + 2
    MCC4 = Application.WorksheetFunction.Find("|", Application.WorksheetFunction.Substitute(Cells(i, 1).Value, ":", "|", 2)) + 2
    MCC5 = Application.WorksheetFunction.Find("|", Application.WorksheetFunction.Substitute(Cells(i, 1).Value, "(", "|", 1)) + 1
    MCC6 = Application.WorksheetFunction.Find("|", Application.WorksheetFunction.Substitute(Cells(i, 1).Value, ")", "|", 1))
    MCC7 = Application.WorksheetFunction.Find("|", Application.WorksheetFunction.Substitute(Cells(i, 1).Value, ":", "|", 1)) + 2
    
    Cells(i, 8) = Mid(Cells(i, 1), MCC, Len(Cells(i, 1)) - MCC + 1)
    Cells(i, 7) = Mid(Cells(i, 1), MCC1, MCC - 12 - MCC1)
    Cells(i, 6) = Mid(Cells(i, 1), MCC2, MCC1 - 12 - MCC2)
    Cells(i, 5) = Mid(Cells(i, 1), MCC3, MCC2 - 14 - MCC3)
    Cells(i, 4) = Mid(Cells(i, 1), MCC4, MCC3 - 10 - MCC4)
    Cells(i, 3) = Mid(Cells(i, 1), MCC5, MCC6 - MCC5)
    Cells(i, 2) = Mid(Cells(i, 1), MCC7, MCC5 - 2 - MCC7)
    
Next i
MsgBox "Done"
Application.ScreenUpdating = True
End Sub
 
Upvote 0
<table border="0" cellpadding="0" cellspacing="0" width="1226"><col style="width: 152pt;" width="202"> <col style="width: 294pt;" width="392"> <col style="width: 122pt;" width="162"> <col style="width: 83pt;" width="111"> <col style="width: 176pt;" width="235"> <col style="width: 93pt;" width="124"> <tbody><tr style="height: 15pt;" height="20"> <td class="xl69" style="height: 15pt; width: 152pt;" height="20" width="202">company name</td> <td class="xl69" style="border-left: medium none; width: 294pt;" width="392">
</td> <td class="xl70" style="width: 122pt;" width="162">
</td> <td style="width: 83pt;" width="111">
</td> <td style="width: 176pt;" width="235">
</td> <td style="width: 93pt;" width="124">
</td> </tr> <tr style="height: 155.25pt;" height="207"> <td class="xl64" style="height: 155.25pt;" height="207">COLUMN A
my company
</td> <td class="xl71" style="width: 294pt;" width="392">COLUMN B
Contact Person 1 : che1 (Core Founder)
Contact Person 2 : che2 (President)
Contact Person 3 : che3 (Senior Executive Vice President)
Contact Person 4 : che4 ( Co-Founder)
Contact Number : 12345
Revenue : 122
Number of Employees : 3
Number of Global Offices : 3 (
Website : www.aaa.cm
</td> <td class="xl63" style="width: 122pt;" width="162">
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height: 15.75pt;" height="21"> <td style="height: 15.75pt;" height="21">Hi texasalynn, you code is working but the output should be like this :
</td> <td>
</td> <td>
</td> <td>
</td> <td>
</td> <td>
</td> </tr> <tr style="height: 15.75pt;" height="21"> <td colspan="6" class="xl68" style="border-right: 1pt solid black; height: 15.75pt;" height="21">THE OUTPUT SHOULD BE LIKE THIS:</td> </tr> <tr style="height: 15.75pt;" height="21"> <td class="xl72" style="height: 15.75pt;" height="21">COMPANY NAME</td> <td class="xl72" style="border-left: medium none;">CONTACT PERSON
</td> <td class="xl72" style="border-left: medium none;">JOB TITLE</td> <td class="xl72" style="border-left: medium none;">PHONE1</td> <td class="xl72" style="border-left: medium none;">OTHER DETAILS</td> <td class="xl73" style="border-left: medium none;">WEBSITE</td> </tr> <tr style="height: 47.25pt;" height="63"> <td class="xl74" style="height: 47.25pt;" height="63">mycompany</td> <td class="xl75">che1</td> <td class="xl75">Core Founder</td> <td class="xl75" align="right">12345</td> <td class="xl76" style="width: 176pt;" width="235">Revenue : 122
Number of Employees : 3
Number of Global Offices : 3
</td> <td class="xl75">www.aaa.cm</td> </tr> <tr style="height: 47.25pt;" height="63"> <td class="xl74" style="height: 47.25pt;" height="63">mycompany</td> <td class="xl75">che2</td> <td class="xl75">President</td> <td class="xl75" align="right">12345</td> <td class="xl76" style="width: 176pt;" width="235">Revenue : 122
Number of Employees : 3
Number of Global Offices : 3
</td> <td class="xl75">www.aaa.cm</td> </tr> <tr style="height: 47.25pt;" height="63"> <td class="xl74" style="height: 47.25pt;" height="63">mycompany</td> <td class="xl75">che3</td> <td class="xl75">Senior Executive Vice President</td> <td class="xl75" align="right">12345</td> <td class="xl76" style="width: 176pt;" width="235">Revenue : 122
Number of Employees : 3
Number of Global Offices : 3
</td> <td class="xl75">www.aaa.cm</td> </tr> <tr style="height: 47.25pt;" height="63"> <td class="xl74" style="height: 47.25pt;" height="63">mycompany</td> <td class="xl75">che3</td> <td class="xl75">Co-Founder</td> <td class="xl75" align="right">12345</td> <td class="xl76" style="width: 176pt;" width="235">Revenue : 122
Number of Employees : 3
Number of Global Offices : 3
</td> <td class="xl75">www.aaa.cm</td> </tr> </tbody></table>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

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