If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > URGENT - extract every odd digit from a numeric string

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-21-04, 08:02
990405 990405 is offline
Registered User
 
Join Date: Jul 2004
Posts: 11
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
Reply With Quote
  #2 (permalink)  
Old 07-21-04, 08:36
DavidCoutts DavidCoutts is offline
Registered User
 
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 08:57.
Reply With Quote
  #3 (permalink)  
Old 07-21-04, 08:40
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
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
Reply With Quote
  #4 (permalink)  
Old 07-21-04, 08:54
DavidCoutts DavidCoutts is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On