Array version of texttocolumn?

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
919
Office Version
  1. 365
Platform
  1. Windows
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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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
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,214,848
Messages
6,121,914
Members
449,054
Latest member
luca142

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
Back
Top