top of page

How to use "VBA split"?


vba split

Strings is just another word for text and in order to write strings you need to use the " quotation signs. This part will go through some practical ways to work with substrings. A great syntax here is the split function. We will starting working with the classic analyst phrase. "Please Fix Thx." and modify that one throughout the examples on the page. Let's start with adding the text parts in to three strings.

A = "Please" B = "Fix" C = "Thx."


Now Let's add them all into one string D for further modifications.

'Let's make sure these are added into one string D.
D = A & " " & B & " " & C

Split Syntax

Split is a practical syntax for dividing a string into multiple ones based on a separator sign.

'Split our text string based on the space.
'The result will be stored in an array containing the 3 text parts we added originally.
MyArray = (Split(D, " "))
​
Debug.Print MyArray(0) 'Please
Debug.Print MyArray(1) 'Fix
Debug.Print MyArray(2) 'Thx.'Add (0) for only returning the first textstring back which is "Please".

'Add (1) for the second etc.. just like a normal array.
MsgBox (Split(D, " ")(0)) 'Please


Learn much more about more text modifications in my bigger article here:


Learn more about VBA here for all my posts: https://www.pls-fix-thx.com/vba

Learn more about Python here for all my posts: https://www.pls-fix-thx.com/python


If you have found this article or website helpful. Please show your support by visiting the shop below.


26 views0 comments

Comments


bottom of page