AllExperts > Experts 
Search      

VB Script

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB Script Answers
Question Library

Ask a question about VB Script
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Miguel Zapico
Expertise
I can answer question about how to use scripts to consolidate data, connect different systems and automate tasks. I have no experience on using VBScript on web programming.

Experience
I have been using VBScript and Windows Scripting Host as my swiss tool for the last 6 years.

Organizations
New York PC users group (NYPC)
Independant Computer Consultants Association (ICCA)

Education/Credentials
Microsoft MCSE in Windows NT

 
   

You are here:  Experts > Computing/Technology > Basic > VB Script > String Manipulation - Extract

Topic: VB Script



Expert: Miguel Zapico
Date: 11/9/2006
Subject: String Manipulation - Extract

Question
Hey Miguel,

Wondering if you could help me out here.  I have headers going from B1:T1 with different stock ticker symbols.  For instance:

Update_^GSPC.csv
Update_AAI.csv
Update_GE.csv

Would all be examples of valid headers.  I would like to get rid of the "Update_" and the ".csv" and be left with just the ticker symbol itself.  Tickers can have a max of 5 characters (^GSPC) and a min of 1 character (F).  The ticker symbols used as headers will be changing so the code must be adaptable enough where I can run it for any set of Ticker symbols.  Some code I have been working on is posted below

Sub Ticker()

Dim strStock As String
arrStock = Array("Update_AAI.csv", "Update_AAPL.csv", "Update_C.csv")
For I = LBound(arrStock) To UBound(arrStock)
   strStock = Mid(arrStock(I), InStr(arrStock(I), "_") + 1)
   strStock = Left(strStock, InStrRev(strStock, ".") - 1)
Next I
End Sub


Thank you for your help

Ed

Answer
Your code works, it extracts to the variable strStock the correct ticker.
In any case, if you want the code to apply to the headers, you could use a different approach, something like:

Sub ExtractTickets()
   With ActiveSheet.Range("B1:T1")
       .Replace What:="Update_", Replacement:="", LookAt:=xlPart
       .Replace What:=".csv", Replacement:="", LookAt:=xlPart
   End With
End Sub

This will get rid of the Update_ and the .csv part on any value on the range of headers.

Hope this helps,
Miguel.

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.