ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find Data in a String (https://www.excelbanter.com/excel-programming/298577-find-data-string.html)

bill

Find Data in a String
 
Within some code in a macro I have a variable
called "Temp" that can hold data like:

BFYS: 94FUND:FUND:0160X4
or
BFYS: 01 02FUND:FUND:0160X4

I want to parse out (capture) two variables:
1. The characters between the first colon and the
first "FUND" word.
2. The characters after the third colon.

In the frist example variable one would equal "94" and two
would be "0160X4."
In the second example they would be "01 02" and "0160X4."

I tried using the "Find" operator, but couldn't get it to
work.

Tom Ogilvy

Find Data in a String
 

temp = "BFYS: 94FUND:FUND:0160X4"
iloc1 = Instr(1,Temp,":",vbTextCompare)
iloc2 = Instr(1,Temp,"fund",vbTextCompare)
? Mid(temp,iloc1+1,iloc2-iloc1-1)
94
iloc3 =
Instr(instr(iloc1+1,temp,":",vbTextCompare)+1,Temp ,":",vbTextcompare)
? right(temp,len(temp)-iloc3)
0160X4

---------------

temp = "BFYS: 01 02FUND:FUND:0160X4"
iloc1 = Instr(1,Temp,":",vbTextCompare)
iloc2 = Instr(1,Temp,"fund",vbTextCompare)
? Mid(temp,iloc1+1,iloc2-iloc1-1)
01 02
iloc3 =
Instr(instr(iloc1+1,temp,":",vbTextCompare)+1,Temp ,":",vbTextcompare)
? right(temp,len(temp)-iloc3)
0160X4

--

Regards,
Tom Ogilvy


"Bill" wrote in message
...
Within some code in a macro I have a variable
called "Temp" that can hold data like:

BFYS: 94FUND:FUND:0160X4
or
BFYS: 01 02FUND:FUND:0160X4

I want to parse out (capture) two variables:
1. The characters between the first colon and the
first "FUND" word.
2. The characters after the third colon.

In the frist example variable one would equal "94" and two
would be "0160X4."
In the second example they would be "01 02" and "0160X4."

I tried using the "Find" operator, but couldn't get it to
work.




Don Guillett[_4_]

Find Data in a String
 
Have a look at instr

--
Don Guillett
SalesAid Software

"Bill" wrote in message
...
Within some code in a macro I have a variable
called "Temp" that can hold data like:

BFYS: 94FUND:FUND:0160X4
or
BFYS: 01 02FUND:FUND:0160X4

I want to parse out (capture) two variables:
1. The characters between the first colon and the
first "FUND" word.
2. The characters after the third colon.

In the frist example variable one would equal "94" and two
would be "0160X4."
In the second example they would be "01 02" and "0160X4."

I tried using the "Find" operator, but couldn't get it to
work.




bill

Find Data in a String
 
Worked great. Thanks for assistance!
I'll add "Instr" function to my "knowledge base."
-----Original Message-----

temp = "BFYS: 94FUND:FUND:0160X4"
iloc1 = Instr(1,Temp,":",vbTextCompare)
iloc2 = Instr(1,Temp,"fund",vbTextCompare)
? Mid(temp,iloc1+1,iloc2-iloc1-1)
94
iloc3 =
Instr(instr(iloc1+1,temp,":",vbTextCompare)

+1,Temp,":",vbTextcompare)
? right(temp,len(temp)-iloc3)
0160X4

---------------

temp = "BFYS: 01 02FUND:FUND:0160X4"
iloc1 = Instr(1,Temp,":",vbTextCompare)
iloc2 = Instr(1,Temp,"fund",vbTextCompare)
? Mid(temp,iloc1+1,iloc2-iloc1-1)
01 02
iloc3 =
Instr(instr(iloc1+1,temp,":",vbTextCompare)

+1,Temp,":",vbTextcompare)
? right(temp,len(temp)-iloc3)
0160X4

--

Regards,
Tom Ogilvy


"Bill" wrote in

message
...
Within some code in a macro I have a variable
called "Temp" that can hold data like:

BFYS: 94FUND:FUND:0160X4
or
BFYS: 01 02FUND:FUND:0160X4

I want to parse out (capture) two variables:
1. The characters between the first colon and the
first "FUND" word.
2. The characters after the third colon.

In the frist example variable one would equal "94" and

two
would be "0160X4."
In the second example they would be "01 02"

and "0160X4."

I tried using the "Find" operator, but couldn't get it

to
work.



.



All times are GMT +1. The time now is 05:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com