Array version of texttocolumn?

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
898
Office Version
  1. 2016
So, I have a string that says

-enter--tab-somerandomletters-tab--enter- (those tabs and enters are t-a-b and e-n-t-e-r not actual tabs and enters). Now, if I put this to a cell A1, I can use TextToColumns like

Code:
range("a1").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
ConsecutiveDelimiter:=True, Other:=True, OtherChar:="-"

which makes it five different cells (B1:F1).

How about splitting it to a five element array? Is there any built-in function for that?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
898
Office Version
  1. 2016
This goes a bit to off-topic, but how is that array "arr" and not "arr()"? Why I can't use parentheses there? Doesn't array always need parentheses?
 
Upvote 0

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,892
I used an untyped declaration for arr. If you do not specify the type then excel declares the variable as Variant. A Variant can contain anything, a built-in type value, an array, an object. In this case the Variant will contain the result of the Split, which is an array of strings.

You could use a typed declaration, in this case an array of strings:

Code:
Dim sArr() As String
 
sArr = Split(Range("A1"), "-")

I'm glad you posted this, as I prefer this typed declaration.
 
Upvote 0

Forum statistics

Threads
1,191,179
Messages
5,985,149
Members
439,943
Latest member
bowlgud2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top