0

I would like to split a String of 41 Characters like the example below: 01288D29424001190601AJGBGR1413190528SR117

Into different columns based on character count from left to right, my constant character count criteria to split the string is:

  5     6     3    6    2   4    4     6    1 1  3

01288 D29424 001 190601 AJ GBGR 1413 190528 S R 117

The string above will be my end result, take into consideration that every space represent a new column.

0

1 Answer 1

2

Place your fieldwidths in B1 through L1 and data in A2. Then in B2 enter:

=LEFT(A2,B1)

and in C2 enter:

=MID($A$2,SUM($B$1:B$1)+1,C$1)

and copy across:

enter image description here

Same logic for VBA:

Sub poiuyt()
    Dim s As String, arr(0 To 10) As String, i As Long
    Dim msg As String

    msg = ""
    s = "01288D29424001190601AJGBGR1413190528SR117"
    wdth = Array(5, 6, 3, 6, 2, 4, 4, 6, 1, 1, 3)
    strt = Array(1, 6, 12, 15, 21, 23, 27, 31, 37, 38, 39)

    For i = 0 To 10
        arr(i) = Mid(s, strt(i), wdth(i))
        msg = msg & vbCrLf & arr(i)
    Next i

    MsgBox msg
End Sub

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.