View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
AA2e72E[_2_] AA2e72E[_2_] is offline
external usenet poster
 
Posts: 93
Default String manipulation from one cell broken up into multiple columns

This is one solution based on your string. I am sure you can adapt it to variations in the string

Sub split(
a = "K500BB-PSD
' Guard against - being last characte
dashExists = InStr(a, "-"
dashExists = dashExists < Len(a
a = Replace(a, "-", ","
For i = 1 To Len(a
If IsNumeric(Mid(a, i, 1)) The
a = Replace(a, Mid(a, i, 1), "," & Mid(a, i, 1)
Exit Fo
End I
Nex
For j = i + 2 To Len(a
If Not IsNumeric(Mid(a, j, 1)) The
a = Left(a, j) & "," & Mid(a, j
Exit Fo
End I
Nex
If dashExists The
While InStrRev(a, ",") < Len(a) -
i = 2 + InStrRev(a, ","
For j = i To Len(a
a = Replace(a, Mid(a, j, 1), "," & Mid(a, j, 1)
Exit Fo
Nex
Wen
End I
MsgBox
End Su