Link to home
Create AccountLog in
Microsoft Excel

Microsoft Excel

--

Questions

--

Followers

Top Experts

Avatar of Ian Bell
Ian Bell🇬🇧

Convert text to Excel column data

I would like to convert the attached text code to separate columns in Excel

Please see attached.

Many thanks

IanConvert_text.xlsx 

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Rob HensonRob Henson🇬🇧

Should be able to use the text to column wizard with "Space" as delimiter.


Avatar of Ian BellIan Bell🇬🇧

ASKER

Hi Rob, would you mind displaying in the earlier attached w/sheet

Thanks

Ian


Avatar of Rob HensonRob Henson🇬🇧

Your sample file seems to have non-standard spaces, copy one and use that as the delimiter in the “Other” option


Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of Ian BellIan Bell🇬🇧

ASKER

Sorry Rob, I don't follow. Is it possible to show me by way of the sample sheet I sent.


Thanks


ASKER CERTIFIED SOLUTION
Avatar of Rob HensonRob Henson🇬🇧

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Ian BellIan Bell🇬🇧

ASKER

Quite an exercise Rob, much harder than I thought.

I may rethink about the source data.

Thanks for your help

Ian


Avatar of Ralf KlattRalf Klatt🇩🇪

Hi,


the result you were looking for should look like this:


User generated image

Is that right?


If yes, then please put this code snippet into a VBA module:


Option Explicit
Sub ConvertRows()     Dim myConvertString As String, myNewString As String, myFinalString As String     Dim mySplitter As Variant     Dim i As Long, rowStart As Long, rowCount As Long     Dim hasAppeared As Boolean     Dim appearedCount As Integer     Dim myWorksheet As Worksheet     Set myWorksheet = Worksheets("Sheet1")     appearedCount = 0     hasAppeared = False     For i = 1 To 1000000         With myWorksheet             If .Cells(i, 1) <> "" Then                 rowCount = rowCount + 1             Else                 Exit For             End If         End With     Next     For rowStart = 1 To rowCount         myFinalString = ""         myNewString = ""         With myWorksheet             myConvertString = .Cells(rowStart, 1).Value             For i = 1 To Len(myConvertString)                 If Asc(Mid(myConvertString, i, 1)) <> 160 Then                     appearedCount = 0                     myNewString = myNewString + Mid(myConvertString, i, 1)                 Else                     If appearedCount = 0 Then                         hasAppeared = True                         If hasAppeared = True Then                             myNewString = myNewString + ";"                             appearedCount = appearedCount + 1                         Else                             appearedCount = 0                         End If                     End If                 End If             Next         End With         mySplitter = Split(myNewString, ";")         For i = 0 To 10             On Error Resume Next             Select Case i                 Case Is < 5                     If mySplitter(i) <> "" Then myFinalString = myFinalString + mySplitter(i) + ";"                 Case Else                     myFinalString = myFinalString + mySplitter(i - 1) & ";" + mySplitter(i)             End Select         Next         mySplitter = Split(myFinalString, ";")         With myWorksheet             Select Case UBound(mySplitter, 1)                 Case 4                     .Cells(rowStart, 3).Value = mySplitter(0)                     .Cells(rowStart, 4).Value = mySplitter(2)                     .Cells(rowStart, 5).Value = mySplitter(3)                 Case 5                     .Cells(rowStart, 3).Value = mySplitter(0)                     .Cells(rowStart, 4).Value = mySplitter(2)                     .Cells(rowStart, 5).Value = mySplitter(3) & " " & mySplitter(5)                 Case Else                     MsgBox "You have to adjust the strings!"             End Select             .Cells(1, 6).Value = "On left how Raisor suggests!"         End With     Next End Sub

Open in new window



Best regards,


Raisor


Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


SOLUTION
Avatar of Ian BellIan Bell🇬🇧

ASKER

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

SOLUTION
Avatar of Ralf KlattRalf Klatt🇩🇪

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

Avatar of Ian BellIan Bell🇬🇧

ASKER

Thanks Raisor, very kind of you.

I've just opened it and works a treat.

Very much appreciated

Ian

Microsoft Excel

Microsoft Excel

--

Questions

--

Followers

Top Experts

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.