[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
Solved

VBA Changing Option Ticker with String Functions

Posted on 2012-08-29
Medium Priority
799 Views
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
Question by:awesomejohn19
• 3

LVL 24

Expert Comment

ID: 38347503
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
``````
Ticker-Convert.xlsm
0

LVL 24

Accepted Solution

Steve earned 2000 total points
ID: 38347535
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
``````
Ticker-Convert.xlsm
0

Author Comment

ID: 38347551
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

LVL 43

Expert Comment

ID: 38347571
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

LVL 24

Expert Comment

ID: 38347662
My second post allows for the variability of the last bit.
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month17 days, 17 hours left to enroll