• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 815
  • Last Modified:

VBA Changing Option Ticker with String Functions

I would like to take
PRX 121117C50000
(Ticker+Space+Year+Month+Day+C+StrikePrice+000)

and convert it to
PRX US 11/17/12 C50
(Ticker+US+Month+/+Day+/+Year+Space+C+50)

Ticker might be one, two, three or four letters.

How can I do this conversion in vba?
0
awesomejohn19
Asked:
awesomejohn19
  • 3
1 Solution
 
SteveCommented:
You can stick this formula into the code module of the workbook and it will do the job:

Function TickerConvert(TickerIn As String) As String

TickerPos = InStr(1, TickerIn, " ", vbTextCompare)
Ticker = Left(TickerIn, TickerPos - 1)
lYear = Mid(TickerIn, TickerPos + 1, 2)
lMonth = Mid(TickerIn, TickerPos + 3, 2)
lDay = Mid(TickerIn, TickerPos + 5, 2)

TickerConvert = Ticker & " US " & lMonth & "/" & lDay & "/" & lYear & " C50"

End Function

Open in new window

Ticker-Convert.xlsm
0
 
SteveCommented:
If the "C50" is vaiable at the end the following will do that too:

Function TickerConvert(TickerIn As String) As String

Dim TickerPos As Long
Dim Ticker As String
Dim lYear As String
Dim lDay As String
Dim sLet As String
Dim sStr As String

TickerPos = InStr(1, TickerIn, " ", vbTextCompare)
Ticker = Left(TickerIn, TickerPos - 1)
lYear = Mid(TickerIn, TickerPos + 1, 2)
lMonth = Mid(TickerIn, TickerPos + 3, 2)
lDay = Mid(TickerIn, TickerPos + 5, 2)
sLet = Mid(TickerIn, TickerPos + 7, 1)
sStr = Mid(TickerIn, TickerPos + 8, 2)

TickerConvert = Ticker & " US " & lMonth & "/" & lDay & "/" & lYear & " " & sLet & sStr

End Function

Open in new window

Ticker-Convert.xlsm
0
 
awesomejohn19Author Commented:
I think it works for most of the conversion.

Thank you for your response. And I am sorry I might have confused you with the way I asked the question.

"C" and "50" are variable to. So there is a posibility that C might be P.
So if the starting value is PRX 121117P50000 then we are going to have P instead of C.

Also if the starting value is PRX 121117C70000 then the ending value is going to be PRX US 11/17/12 C70

So those values may vary too. How can we modify the code?
0
 
Saqib Husain, SyedEngineerCommented:
Try

Sub cvstr()
Dim tstr As String, nstr As String
tstr = "PRX 121117C50000"
nstr = Left(tstr, InStr(tstr, " "))
tstr = Replace(tstr, nstr, "")
nstr = nstr & "US " & Mid(tstr, 3, 2) & "/" & Mid(tstr, 5, 2) & "/" & Left(tstr, 2) & " " & Mid(tstr, 7, 1) & " " & Mid(tstr, 8, 2)
End Sub
0
 
SteveCommented:
My second post allows for the variability of the last bit.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now