VBA Split a String in two parts (1 Viewer)

AccOUCH

Registered User.
Local time
Today, 05:01
Joined
Sep 27, 2018
Messages
25
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
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:01
Joined
May 21, 2018
Messages
8,463
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
 

Users who are viewing this thread

Top Bottom