Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a string with multiple delimiters in vba excel?

Tags:

excel

vba

I want to split a string with multiple delimiters using Excel VBA. One of the strings is:

d1-d2 d3 d4  

We have a dash and a space as two delimiters. I tried the split function but it only does it with one delimiter.

like image 574
infinitloop Avatar asked Oct 06 '11 21:10

infinitloop


People also ask

How do I split a string in Excel VBA?

The Microsoft Excel SPLIT function will split a string into substrings based on a delimiter. The result is returned as an array of substrings. The SPLIT function is a built-in function in Excel that is categorized as a String/Text Function. It can be used as a VBA function (VBA) in Excel.


1 Answers

You could first do a Replace on the string first and then do the split:

newString = Replace(origString, "-", " ")
newArray = Split(newString, " ")
like image 52
PaulStock Avatar answered Sep 28 '22 22:09

PaulStock