[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
5
Medium Priority
?
799 Views
Last Modified: 2012-08-29
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
Comment
Question by:awesomejohn19
  • 3
5 Comments
 
LVL 24

Expert Comment

by:Steve
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

Open in new window

Ticker-Convert.xlsm
0
 
LVL 24

Accepted Solution

by:
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

Open in new window

Ticker-Convert.xlsm
0
 

Author Comment

by:awesomejohn19
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

by:Saqib Husain, Syed
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

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question