String Text to Columns

ionelz

Board Regular
Joined
Jan 14, 2018
Messages
248
Office Version
  1. 365
Platform
  1. Windows
[FONT=&quot]In my TABLE, Column1 have this type of Strings: A10 B15 A21 G33 B121 A1000 (THIS IS TEXT)[/FONT][FONT=&quot][/FONT][FONT=&quot]
I would like to SPLIT these Strings to Corresponded Columns, so 10 goes to Column A, 15 to Column B, 21 to Column A, 33 to Column G, 121 to Column B, 1000 to Column A, THIS IS A TEXT to Column2. So in Column A is 10,21,1000 in Column B is 15,121 in Column G is 33 and in Column2 THIS IS A TEXT. Text in () should always go to Column1[/FONT]
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
As long as the text within () is at the end of the cell, the following code should do what you're asking.

It first splits the cell that includes (THIS IS TEXT) to cells AA# and AB#, then loops through each part of the array, adding values to each respective column.

Let me know if you have any issues.

Code:
Sub ArrayLoop()

For i = 1 To Range("A" & Rows.Count).End(xlUp).row

    If InStr(1, Range("A" & i).Value, " (") Then
        cellSplit = Split(Range("A" & i).Value, " (")
        Range("AB" & i).Value = "(" & cellSplit(UBound(cellSplit))
        Range("AA" & i).Value = cellSplit(LBound(cellSplit))
        Range("A" & i).Value = ""
    Else
        Range("AA" & i).Value = Range("A" & i).Value
        Range("A" & i).Value = ""
    End If
    
    sArray = Split(Range("AA" & i).Value, " ")
    
    For x = 0 To UBound(sArray)
        cellColumn = Left(sArray(x), 1)
        cellValue = Right(sArray(x), Len(sArray(x)) - 1)
        
        If Range(cellColumn & i).Value = "" Then
            Range(cellColumn & i).Value = cellValue
        Else
            Range(cellColumn & i).Value = Range(cellColumn & i).Value & ", " & cellValue
        End If
    Next x
    
    If Range("AB" & i).Value <> "" Then
        Range("A" & i).Value = Range("A" & i).Value & ", " & Range("AB" & i).Value
    End If
    
Next i

End Sub
 
Upvote 0
I do not know VBA, so is hard for me to edit/debug
I would be happy if in my TABLE1 from Sheet1 I could do with a formula this : SPLIT the ColumnA with string in 2 columns, ColumnB and ColumnC
So ColumnA with String : N200 K30 V25 N12 B167 (THIS IS AN TEXT) will split in ColumnB : N200 K30 V25 N12 B167 and ColumnC : THIS IS AN TEXT
And say : ColumnB (Sheet1) to autofill to ColumnN(sheet2)


As long as the text within () is at the end of the cell, the following code should do what you're asking.

It first splits the cell that includes (THIS IS TEXT) to cells AA# and AB#, then loops through each part of the array, adding values to each respective column.

Let me know if you have any issues.

Code:
Sub ArrayLoop()

For i = 1 To Range("A" & Rows.Count).End(xlUp).row

    If InStr(1, Range("A" & i).Value, " (") Then
        cellSplit = Split(Range("A" & i).Value, " (")
        Range("AB" & i).Value = "(" & cellSplit(UBound(cellSplit))
        Range("AA" & i).Value = cellSplit(LBound(cellSplit))
        Range("A" & i).Value = ""
    Else
        Range("AA" & i).Value = Range("A" & i).Value
        Range("A" & i).Value = ""
    End If
    
    sArray = Split(Range("AA" & i).Value, " ")
    
    For x = 0 To UBound(sArray)
        cellColumn = Left(sArray(x), 1)
        cellValue = Right(sArray(x), Len(sArray(x)) - 1)
        
        If Range(cellColumn & i).Value = "" Then
            Range(cellColumn & i).Value = cellValue
        Else
            Range(cellColumn & i).Value = Range(cellColumn & i).Value & ", " & cellValue
        End If
    Next x
    
    If Range("AB" & i).Value <> "" Then
        Range("A" & i).Value = Range("A" & i).Value & ", " & Range("AB" & i).Value
    End If
    
Next i

End Sub
 
Upvote 0
Could you tell me how to attach an EXCEL file so I can better describe my question
 
Upvote 0
Could you tell me how to attach an EXCEL file so I can better describe my question
Post a copy of your workbook to DropBox, make sure it it shareable (I think you have to do that with DropBox), and then post the URL they give you in a response here.
 
Upvote 0
I did a Copy /Paste


StringABCDGK
A10 B20 G300 A103 K35 A48 A476 D12 A66 A76 (THIS IS AN TEXT)10,103,48,476,66,7620 30035
A49 C100 G249 100 2
A10 C20 K2110 20 21
A40 B22 D21 A3340,3322 21
Split Numbers after character in Column String to "coresponded" Columns as shown
A - have Multiple Repetitions (6 MAX) , the rest B,C,D,E,F ar unique per String
If possible the SPLIT should stop before character ( so look only in the left side of character (

<colgroup><col><col><col span="2"><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,212
Members
449,074
Latest member
cancansova

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