PDA

View Full Version : [SOLVED] Split String After 15 Characters



Ethan
10-05-2013, 11:45 PM
Hello all,

I'd like to split a string after each 15th character into different cells.
i.e:
a1: hjh3 hjkh khhkjh jkhkh hkghf fg ghf hjkj lj ghjg gkjlh
a2: hjh3 hjkh khhkj
a3: h jkhkh hkghf f
a4: g ghf hjkj lj g
a5: hjg gkjlh

Any ideas?

mancubus
10-06-2013, 03:26 AM
hi.

try this.



Sub Split_Into_Equal_Parts()


Const dlmtr As Long = 15
Dim length As Long, parts As Long, i As Long

length = Len(Range("A1"))

If length Mod dlmtr = 0 Then
parts = length \ dlmtr
Else
parts = length \ dlmtr + 1
End If

For i = 0 To parts - 1
Range("A" & i + 1).Offset(1) = Mid(Range("A1"), (i * dlmtr) + 1, dlmtr)
Next


End Sub

Ethan
10-06-2013, 03:40 AM
Thanks!

mancubus
10-06-2013, 11:23 AM
you are welcome.