Could you post the examples of the text? I cannot download.
REACTIVE 1/160
> 100
REACTIVE >650
Positive 482.5
NON REACTIVE 0.620
REACTIVE >500
Negative 1/80
NON REACTIVE 0.240
REACTIVE > 600
NON REACTIVE 0.130
Negative 1/40
Positive..............482.5
40what number do you want for this one
Negative 1/40
40? or 0.025?
0.620and this one
NON REACTIVE 0.620
0.620? or 620?
i.e. decimal numbers, not integer?
Also, are your numbers always on the right or can they also be on the left or in the middle?
@ranman, looking at the file there are multiple spaces e.g. substitute a space for each dot in this example
very thankscan you provide some examples of numbers 'in the middle'
do they include things like 0.620 and 1/40?
in order to extract the numbers, you need to be able to determine a pattern - e.g. if always on the right, then inspect the last few characters.
With what you have said so far there is no pattern, further complicated by the numbers themselves not having a pattern either.
Is there any way you can tidy the input up before loading it into access?
best I can suggest at the moment is something like
first step - convert spaces to >
second step convert / to >
third step 'val' everything after the last > which will convert any consecutive number characters.
something like
val(mid(replace(replace(trim(myfield)," ",">"),"/",">"),1+instrrev(replace(replace(trim(myfield)," ",">"),"/",">"),">"))
but this won't work if the characters after a 'middle' number has a space, > or / character - because instrrev looks for the last iteration of > in the string.
Positive480.5provide an example of what
means
Function Seperate_Digits(T)
'T = Text From Query
For i = 1 To Len(T)
'the ascii number of each number
C = Asc(Mid(T, i, 1))
'ascii numbers we want
'46= .
'47= /
'48= 0
'49= 1
'50= 2
'51= 3
'52= 4
'53= 5
'54= 6
'55= 7
'56= 8
'57= 9
Select Case C
Case 46 To 57
Which_Letter = Which_Letter & Mid(T, i, 1)
End Select
Next i
Seperate_Digits = Which_Letter
End Function
'---------------------------------------------------------------------------------------
' Procedure : fExtractStrNums
' Author : user
' Date : 2/27/2009
' Purpose : To extract only numerics from a string of mixed alpha,
'numerics and special chars.
'---------------------------------------------------------------------------------------
'
Function fExtractStrNums(ByVal strInString As String) As String
' From Dev Ashish
'(Q) How do I extract only characters from a string which has both numeric and alphanumeric characters?
'(A) Use the following function. Note that the If loop can be modified to extract either both Lower and Upper case character or either
'Lower or Upper case characters.
'************ Code Start **********
Dim lngLen As Long, strOut As String
Dim i As Long, strTmp As String
10 On Error GoTo fExtractStrNums_Error
20 lngLen = Len(strInString)
30 strOut = ""
40 For i = 1 To lngLen
50 strTmp = Left$(strInString, 1)
60 strInString = Right$(strInString, lngLen - i)
'ADJUSTED CODE TO GET ONLY NUMERICS and ./>- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
70 If (Asc(strTmp) >= 48 And Asc(strTmp) <= 57) _
Or strTmp = ">" Or strTmp = "." Or strTmp = "-" Or strTmp = "/" Then
80 strOut = strOut & strTmp
90 End If
100 Next i
110 fExtractStrNums = strOut
120 On Error GoTo 0
130 Exit Function
fExtractStrNums_Error:
140 MsgBox "Error " & err.number & " (" & err.Description & ") in procedure fExtractStrNums of Module Module1"
End Function
Falcon,
Please explain fully what makes "hello >1 /98" ===> 98???
and "Negative 1/40" ====>40???
It seems to me that your post's title is incorrect.
However, you can use the function I provided and add necessary logic to deal with these "fractions".
Did you try the function I provided?
Function Seperate_Digits(T As String) As String
Dim i As Integer
Dim C As String
Dim Which_Letter As String
'T = Text From Query
If Len(T & "") = 0 Then
Seperate_Digits = ""
Exit Function
End If
For i = 1 To Len(T)
'the ascii number of each number
C = Asc(Mid(T, i, 1))
'ascii numbers we want
'46= .
'47= /
'48= 0
'49= 1
'50= 2
'51= 3
'52= 4
'53= 5
'54= 6
'55= 7
'56= 8
'57= 9
Select Case C
Case 46, 48 To 57
Which_Letter = Which_Letter & Mid(T, i, 1)
Case 47
Which_Letter = ""
End Select
Next i
Seperate_Digits = Which_Letter
End Function