Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    11

    Unanswered: URGENT - extract every odd digit from a numeric string

    URGENT - extract every odd digit from a numeric string
    I have a problem in which I would like to extract every odd digit in the length of a numeric string and then return this as a combined result

    Could a simple function be derived for Excel?

    Below is given an example:

    Original Odd digit Result
    0 1 0
    9 2
    7 3 7
    1 4
    0 5 0
    2 6
    1 7 1
    0 8
    5 9 5
    1 10
    1 11 1
    1 12
    1 13 1
    1 14
    4 15 4
    1 16
    0 17 0
    0 18
    1 19 1
    0 20
    5 21 5
    1 22
    1 23 1
    2 24
    1 25 1
    0 26
    1 27 1
    1 28
    0 29 0
    8 30
    1 31 1
    0 32
    8 33 8
    1 34
    0 35 0
    1 36


    i.e. resulting combination

    070151140151110180

  2. #2
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    Code:
    Function OddChars(ByVal strIn As Range)
        Dim LenText As Integer
        Dim InputData As String
        Dim CharSplit As Variant
        Dim I As Integer
        Dim Output As String
        
        
        InputData = strIn.Value
        LenText = Len(InputData)
        
        ReDim CharSplit(LenText) As Variant
        
        CharSplit(1) = Left(InputData, 1)
        
        For I = 2 To LenText
            CharSplit(I) = Right(Left(InputData, I), 1)
        Next I
        
        For I = 1 To LenText
            If I mod 2 = 1 Then 'Edited for error
                Output = CStr(Output & CharSplit(I))
            End If
        Next I
    
        OddChars = Output
    End Function
    HTH
    David
    Last edited by DavidCoutts; 07-21-04 at 09:57.

  3. #3
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    I am sure it can be done without too much effort, but excuse me for being a liitle dense, how does the 'resulting combination' relate to the 'origional odd digit result' ?

    MTB

  4. #4
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    Mike

    The original Number goes from top to bottom on the left hand side
    The Middle column is just the count from 1 to 36
    The Right Column is the same number with even numbers removed

    the result being the sum of all the right hand column,
    my function sorts this out by taking a string filling it to an array
    if the value of I is odd then add his to a string

    David

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •