Seperating characters into different cells RRS feed

  • Question

  • Is there a way of seperator characters into different cells of excel spreadsheets

    like from cell A1;

    FHKDFIN     22222222001




    FH in A1

    KDFIN      in B1

    22222222 in C1

    and 001 in d1


    Note: Characters are not always fix they are dynamic

    Sunday, October 7, 2007 3:59 PM

All replies

  • Hi again!

    Need at least some algorithm of separating
    Sunday, October 7, 2007 10:15 PM
  • Have you tried writing a bit of VBA to do it?


    Here is what the Help system says about it


    Parses a range of data and breaks it into multiple cells. Distributes the contents of the range to fill several adjacent columns; the range can be no more than one column wide.

    expression.Parse(ParseLine, Destination)

    expression    Required. An expression that returns a Range object.

    ParseLine    Optional Variant. A string that contains left and right brackets to indicate where the cells should be split. For example, "[xxx][xxx]" would insert the first three characters into the first column of the destination range, and it would insert the next three characters into the second column. If this argument is omitted, Microsoft Excel guesses where to split the columns based on the spacing of the top left cell in the range. If you want to use a different range to guess the parse line, use a Range object as the ParseLine argument. That range must be one of the cells that's being parsed. The ParseLine argument cannot be longer than 255 characters, including the brackets and spaces.

    Destination    Optional Variant. A Range object that represents the upper-left corner of the destination range for the parsed data. If this argument is omitted, Microsoft Excel parses in place.


    This example divides telephone numbers of the form 206-555-1212 into two columns. The first column contains only the area code, and the second column contains the seven-digit telephone number with the embedded hyphen.

    Worksheets("Sheet1").Columns("A").Parse _
        parseLine:="[xxx] [xxxxxxxx]", _

    Remember to take out the  two _   (underscore characters) so that it all goes on the same line.


    Have fun.


    Sebastian Wheaterbix


    Friday, April 25, 2008 1:39 PM
  • Using your example string - FHKDFIN     22222222001



    I  spent some time testing and found that the following works fine (must include "x" for spaces)...



    Code Snippet
    Private Sub CommandButton1_Click()

    Worksheets("Sheet1").Columns("A").Parse _
        parseLine:="[xx] [xxxxxxxx] [xxxxxxxx] [xxx]", _

    End Sub



    Except that the "001" value in cell D1 is displayed as "1". The leading zeros are not displayed.

    I tried changing the NumberFormat with...


    Code Snippet

    Selection.NumberFormat = "@"



    However, that has no effect.


    Anyone have a suggestion as to how to treat the zero values so they are displayed?


    Saturday, April 26, 2008 4:39 AM
  • Hi, if you want an alternative to the above you can write the parsing yourself. Attach a keystroke to the below code in a new module and the active cell will be parsed according to your rules above.


    Code Snippet

    Public Sub Splitter()
    Dim str As String
    Dim lngRow, lngCol As Long

    With ActiveCell
        lngRow = .Row
        lngCol = .Column
        str = ActiveCell.Value
    End With
    With ActiveSheet
        .Cells(lngRow, lngCol) = Left$(str, 2)
        .Cells(lngRow, lngCol + 1) = Mid$(str, 3, 5)
        .Cells(lngRow, lngCol + 2).NumberFormat = "@"
        .Cells(lngRow, lngCol + 2) = Mid$(str, 13, 8)
        .Cells(lngRow, lngCol + 3).NumberFormat = "@"
        .Cells(lngRow, lngCol + 3) = Mid$(str, 21, 3)
    End With
    End Sub



    Saturday, April 26, 2008 1:30 PM