Query Question?

phimz196

New Member
Joined
Oct 6, 2004
Messages
42
I have string field in a table the had different spacing.

Examples:

4010252-1-NA-OPT-NA-1-ICA-bal
495390-2-NA-OPT-NA-74-ICAS-bal
490861-1-na-opt-na-4-icas-kn

I am trying to pull all of the numbers after the fifth - (dash)

So the results would be:

1
74
4

Is there any funcation that i can use?

Thanks for the help...
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I would suggest writing a function that accepts this field as input, then do a look looking for the "-". After finding the "-" for the5th time, pass back from the function all the numbers between the 5th and the 6th "-". To find the first occurance, and subsequent ones to, use the function Instr(). For more info on Instr, look it up in Access help.
 
Upvote 0
If you have access 2000 or better you can use the split() function.

Code:
Function Parser(strIn As String, strDelimiter As String, intPosition As Integer)
Dim array1
array1 = Split(strIn, strDelimiter)
Parser = array1(intPosition)
End Function

? Parser("490861-1-na-opt-na-4-icas-kn","-",5)

Use in a query like Parser([FieldName],"-",5)

HTH,
CT
 
Upvote 0
CT,
Thanks for your posting. I keep forgetting about Split() because I have not used it yet. Keep this up and hopefully I will use it soon instead of my loops.
 
Upvote 0
because split() returns an array you could actually write the function like this:
Code:
Public Function Parser(strIn As String, strDelimiter As String, intPosition As Integer)
Parser = Split(strIn, strDelimiter)(intPosition)
End Function

I just think that's kind of neat :biggrin:
 
Upvote 0
If the bit before your number is always NA-OPT-NA- then you could use the query:
Code:
SELECT 
MID([fldCode],InStr([fldCode],"NA-OPT-NA-")+10,(Instr(InStr([fldCode],"NA-OPT-NA-")+10,[fldCode],"-"))-(InStr([fldCode],"NA-OPT-NA-")+9)-1) as Final
FROM Table1;
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,742
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top