separting text to cloumn

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Sorry I am adding some more info that might help
All data now are in one cell (account, name, and address). Unfortunately, I am having troubles delineating the data. I have tried "text to columns" and some formulas but not luck. I am hoping I could put account, name, and address in their own column.
 
Upvote 0
Upvote 0
Account | Name | address
1010023 | John Smith | Rome Italy


Thank you.
 
Last edited:
Upvote 0
Account | Name | address
1010023 | John Smith | Rome Italy
Give this macro a try (make sure to set the StartRow variable to the actual starting row for your data)...
Code:
[table="width: 500"]
[tr]
	[td]Sub SplitIntoColumns()
  Dim R As Long, X As Long, StartRow As Long, LastRow As Long, AddrStart As Long
  Dim Txt As String, Result As Variant
  [B][COLOR="#FF0000"]StartRow = 4[/COLOR][/B]
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  ReDim Result(StartRow To LastRow, 1 To 3)
  For R = StartRow To LastRow
    Txt = Trim(Replace(Cells(R, "A").Value, "/", " "))
    AddrStart = InStr(Txt, " ") + 1
    Result(R, 1) = Left(Txt, AddrStart - 2)
    For X = AddrStart To Len(Txt)
      If Mid(Txt, X, 1) Like "#" Then
        Result(R, 2) = Mid(Left(Txt, X - 1), AddrStart)
        Result(R, 3) = Mid(Txt, X + 2)
        Exit For
      End If
    Next
  Next
  Range("B1:D1") = Array("Account", "Name", "Address")
  Range("B2").Resize(UBound(Result), 3) = Result
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Thanks for your reply. I tried to put this code in VBA window but then what I am suppose to do?
Sorry I am asking this question because I am not that familiar with VBA. Thank you so much.

Give this macro a try (make sure to set the StartRow variable to the actual starting row for your data)...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub SplitIntoColumns()
  Dim R As Long, X As Long, StartRow As Long, LastRow As Long, AddrStart As Long
  Dim Txt As String, Result As Variant
  [B][COLOR=#ff0000]StartRow = 4[/COLOR][/B]
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  ReDim Result(StartRow To LastRow, 1 To 3)
  For R = StartRow To LastRow
    Txt = Trim(Replace(Cells(R, "A").Value, "/", " "))
    AddrStart = InStr(Txt, " ") + 1
    Result(R, 1) = Left(Txt, AddrStart - 2)
    For X = AddrStart To Len(Txt)
      If Mid(Txt, X, 1) Like "#" Then
        Result(R, 2) = Mid(Left(Txt, X - 1), AddrStart)
        Result(R, 3) = Mid(Txt, X + 2)
        Exit For
      End If
    Next
  Next
  Range("B1:D1") = Array("Account", "Name", "Address")
  Range("B2").Resize(UBound(Result), 3) = Result
End Sub
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Thanks for your reply. I tried to put this code in VBA window but then what I am suppose to do?
Sorry I am asking this question because I am not that familiar with VBA. Thank you so much.

HOW TO INSTALL MACROs
------------------------------------
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (SplitIntoColumns) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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