Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 01-24-2019, 03:26 AM   #1
AccOUCH
Newly Registered User
 
Join Date: Sep 2018
Posts: 25
Thanks: 23
Thanked 0 Times in 0 Posts
AccOUCH is on a distinguished road
VBA Split a String in two parts

Hello,

I'm trying to obtain two codes from this string: "HL PNX-70[15200]"
But with this code, I obtain two times the same output: "HL PNX-70". So, the code is not properly done.
How to obtain the output '15200' from the above mentioned String?

Code:
Private Sub Comando221_Click()
MsgBox (Right(Split("HL PNX-70[15200]", "[")(0), 50))
MsgBox (Left(Split("HL PNX-70[15200]", "[")(0), 50))
End Sub

AccOUCH is offline   Reply With Quote
Old 01-24-2019, 04:37 AM   #2
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,397
Thanks: 436
Thanked 805 Times in 780 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: VBA Split a String in two parts

If it always going to be in that format and length, use the Mid function

https://docs.microsoft.com/en-us/off...p/mid-function
__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is online now   Reply With Quote
Old 01-24-2019, 04:41 AM   #3
MajP
Newly Registered User
 
Join Date: May 2018
Location: USA baby
Posts: 1,858
Thanks: 36
Thanked 566 Times in 533 Posts
MajP has a spectacular aura about MajP has a spectacular aura about
Re: VBA Split a String in two parts

Code:
Public Sub TestIt()
  Dim str As String
  Dim strLeft As String
  Dim strRight As String
  str = "HL PNX-70[15200]"
  
  strLeft = Trim(Split(str, "[")(0))
  Debug.Print strLeft
  
  strRight = Trim(Split(str, "[")(1))
  strRight = Trim(Replace(strRight, "]", ""))
  Debug.Print strRight
End Sub
Here is both. left side or right side
HL PNX-70
15200

MajP is offline   Reply With Quote
Reply

Tags
access , split , strings , vba

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Split table in 4 equivalent parts by 3 criteria iordache09 Queries 11 12-19-2014 08:20 AM
split string into parts but... lala Modules & VBA 9 12-05-2011 08:49 PM
split name field into parts supmktg Modules & VBA 3 09-05-2005 10:35 PM
Embolden some parts of string davedynamic Modules & VBA 12 10-31-2001 06:29 PM
OK, Can I pause the macro or split to parts? Rich_Lovina Macros 3 10-19-2001 12:14 PM




All times are GMT -8. The time now is 11:53 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World