index > Visual Basic for Applications (VBA) > String parsing in VBA 6.3

String parsing in VBA 6.3


New to VB.

Simply trying to parse the zip code out of a string and placing the zip code into a new string. Looking at the Split method, but unable to get code working w/o errors.

Sample string I am trying to parse is:

'Bakersfield,? CA? 93309

Any suggestions on the code snippet to remove the zip out of this string?

Thanks in advance. CT

ctrahan

well you could split it by the spaces but that would create 3 items and the last one would be the zip code:

Dim theItems() as String = theString.Split(new Char() {" "})

MessageBox.Show(theItems(theItems.Length - 1).ToString())

 

another way would be to get the lastindex of a space from that string: 

Dim theZipCode as String = theString.SubString(theString.LastIndexOf(" "))

 

One other way would be to use Regex - regular expressions but can be expensive. I'm not great at regex but some members here are and there is of course the resources from your fav search engine ;-)

Does this help?

 




Need 2 be back @ MS - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
ahmedilyas

Thank you for the quick response. I just figured out that I am actually inside the VBA 6.3 IDE launched from Excel. It seems the variable declaration is not as advanced in VBA as VB Express edition.

Would you know how to do this string extraction inside VBA 6.3 using a module? This way I am already 'inside' my Excel worksheet.

Thanks

CT

ctrahan

Ah!

Thread moved to the appropriate forum, they will help you more hopefully




Need 2 be back @ MS - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
ahmedilyas
reply 4

You can use google to search for other answers

 

More Articles

• IIf function within MS Access
• Calling procedure upon deactivate
• VBA code in Dutch
• Excel memory issues
• Open an excel file
• Customized Scheduler in Outlook 2003 Calendar
• Function which get range arg.
• passing data from a form to a module
• VBA resources
• (Vitual IP Problem ) Web Farming using NLB in windows server 2003...
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

• How to put text in a listbox heads ?
• empty datagrid
• Help: How can I deploy my VBA?
• Defining objects within a cell range
• Error 3251 using ADO & VBA to drop a
• CDONTS
• Picture Question
• Send Email via outlook through excel
• How to create a hyperlink in Excel Chart.
• Set oHyper = ActiveDocument.Hyperlinks.A
• print out to .pdf or calling a macro wit
• Put Certain E-mail Address in FROM Field
• Can no longer enter wscript for debug
• Excel macro not able to SetSourceData fo
• Novice VBA user trying to consolidate in

Hot Articles

• Array lengths
• How to retrieve worksheet name using ADO?
• If your users reference an XLA on the ne
• Outlook Macro VB - choose second mail box?
• Retrieve IBM Workplace Forms data into E
• Excel shape classname in Windows API
• macro script?
• Observation AND Request
• Order By DateDiff() in Access Report
• Programming with MULTIPAGE
• Access Project and View Record source
• Password question
• Multithreading, Callback & VBA in Po
• add table to a word document
• VB.Net to VBA?

Recommend Articles

• Textbox won't keep new values after work
• VBA 6.4 now available on MSDN Subscription
• Get Excel Sheet Names
• Send Email via outlook through excel
• Unsuccessfully trying to open Power Poin
• [Access 2003] [ADO Excel Connection] Run
• Newsbyte: VSTO "Cypress" Offic
• Serial Port Communication Using MS Acces
• Referring to a range on another workshee
• Excel VB problem
• Excel Server Using VBA
• Extract text within several tables in wo
• Hyperlink to a subroutine
• Left and Right Margins in special cases
• CreateProcessA problem - no DOS windows