VBA SPLIT FUNCTION

  • Thread starter Thread starter PCC
  • Start date Start date
P

PCC

I need to get the left portion of a variable length string
up to the comma delimiter. I tried the Split function but
apparently I'm not getting it right.
For Example:

Ex1:
The string: "Duck, Donald - 8765"
I want to get "Duck"

Ex2:
The String: "Mouse, Mickey - 3456"
I want to get "Mouse"
 
Dim str As String
str = "Duck, Donald"
MsgBox Left(str, InStr(str, ",") - 1)
 
Hi
try
sub foo()
Dim str As String
v_str = "Duck, Donald - 8765"
MsgBox Left(v_str, InStr(v_str, ",") - 1)

end sub
 
If you wish to use the Split function, here is one way...

Sub Demo()
Dim s As String
s = "Duck, Donald - 8765"
Debug.Print Split(s, ",")(0)

s = "Mouse, Mickey - 3456"
Debug.Print Split(s, ",")(0)
End Sub

returns:
Duck
Mouse
 
Don't know what the split function is except to split windows.

One way is to use InStr and search for the comma to get it's position, then
use the LEFT function to extract that many characters - 1.

TH
 
My first time using this passport.
It's great and so is your response
thanx a lot
 
My first time using this passport.
It's great and so is your response
thanx a lot
 
My first time using this passport.
It's great and so is your response
thanx a lot
 
It works
thank you...thank you...thank you... alot
-----Original Message-----
Don't know what the split function is except to split windows.

One way is to use InStr and search for the comma to get it's position, then
use the LEFT function to extract that many characters - 1.

TH



.
 
xl2k added Split, join, round (and more??) to its vba arsenal.

Split takes a text string and splits it up based on a chosen character and
returns an array with each piece as a different element.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top