csutaria

New Member
Joined
Apr 3, 2009
Messages
20
Does anyone know the syntax to convert text to table using 2 delimiters (~ to switch to the next column and "&" to switch to the next row)?

I'm planning to use it as part of a macro for MS Project 2003 but I figure it would be pretty much the same in excel.

Any help would be greatly appreciated.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

schielrn

Well-known Member
Joined
Apr 4, 2007
Messages
6,939
I'm not following exactly what you are asking here?

Do you have a lot of data in a cell separated by ~ and & and then depending on those to move the data to the next column or row?
 

ZVI

MrExcel MVP
Joined
Apr 9, 2008
Messages
3,836
Office Version
  1. 2016
  2. 2010
  3. 2007
Platform
  1. Windows
Hi,

Try these macros and choose the applicable one:

Rich (BB code):
<font face=Courier New>
' Using of Excel .TextToColumns method
Sub TxtToExcelColumns(Txt As String, DestUpperLeftCell As Range)
  Dim arr
  arr = Split(Txt, "&")
  With DestUpperLeftCell.Cells(1, 1).Resize(UBound(arr) + 1)
    .Value = arr
    .TextToColumns Destination:=.Cells(1, 1), _
                   ConsecutiveDelimiter:=False, _
                   DataType:=xlDelimited, _
                   Other:=True, OtherChar:="~"
  End With
End Sub

Sub Test_TxtToExcelColumns()
  Dim Txt As String
  Txt = "Txt1.1~Txt1.2~Txt1.3~1~2~3&Txt2.1~Txt2.2~Txt2.3~4~5~6"
  ' If Txt is in [A1] cell then uncomment the line below
  'Txt = Range("A1").Value
  TxtToColumns Txt, Range("A2")
End Sub
</FONT>

Rich (BB code):
<font face=Courier New>
' Using of Replace function
Function TxtToTabColumns(Txt As String)
  TxtToTabColumns = Replace(Replace(Txt, "&", vbLf), "~", vbTab)
End Function

Sub Test_TxtToTabColumns()
  Dim Txt As String
  Txt = "Txt1.1~Txt1.2~Txt1.3~1~2~3&Txt2.1~Txt2.2~Txt2.3~4~5~6"
  MsgBox TxtToTabColumns(Txt)
End Sub</FONT>

Regards,
Vladimir
 

Forum statistics

Threads
1,137,354
Messages
5,681,002
Members
419,948
Latest member
Sbakker1

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
Top