Parsing a string with numbers, hypens, and commas

Tweeks

Board Regular
Joined
Jul 27, 2004
Messages
52
Hi there,

I have a string that will typically look like:

1,2,5,6,10-14,28

I would like each of the values between the ","'s as a seperate value preferably in an array in VBA.

Is this possible? I've done something simliar in VB a long while ago and its lost on me as to how to do this in VBA if it is at all possible.

Thanks in advance.

edit: Using Excel 97 on a Windows NT system.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Yep use split like the above poster said.

arrString = split(string,",")

acess the values as suchs arrString(0) etc
 
Upvote 0
Sounds ideal but i dont think excel 97 has split. It doesn't recognise it, 'Complie Error - Sub or Function not defined'

Could i code Split myself?
 
Upvote 0
Thats a last option, mainly because when i record doing that switch it specifies how many columns, but i could have from 1 to 30 depending on the string. It would be much much easier to have an array variable that i can loop through.
 
Upvote 0
Then i would think you will have to use a loop and go through and stuff each value into an array. THen once you have it filled out redim it using preserve
 
Upvote 0

Forum statistics

Threads
1,213,550
Messages
6,114,265
Members
448,558
Latest member
aivin

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