Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spliting Variable

Status
Not open for further replies.

drewduncan

Programmer
Apr 3, 2003
38
0
0
GB
Hi:

I am import a CSV file line by line.
I store the whole line in a variable.

Variable may look like:
56,HighStreet,London

Is there a function that can split the variable to the commas e.g. can i 'grab' then 56, then the HighStreet then London?

Any help appreciated
 
Hi,

Are you doing this in VBA? I assume you are if you're using a variable.

The
Code:
Split
function creates an Array which holds sections of a tring Variable, in your example

Code:
Public Sub TestSplit()

Dim strString As String 'Your variable value
Dim strArray As Variant 'Array to hold the elements of the variable
Dim intX As Integer

strString = "56,HighStreet,London" 'Define the variable value

strArray = Split(strString, ",") 'Breakdown the variable at each occurance of ','

For intX = LBound(strArray) To UBound(strArray) 'Iterate through the elements of the variable

    Debug.Print strArray(intX) 'Shows each element in the Immediate window. You code to use the variable element goes here.

Next intX

End Sub

Hope this helps

Leigh Moore
Solutions 4 MS Office Ltd
 
Are you doing this in VBA? I assume you are if you're using a variable.

And the fact that you're in the Microsoft: Access Modules (VBA Coding) Forum is also a bit of a give away!!



Leigh Moore
Solutions 4 MS Office Ltd
 
Thanks Leigh:

Works great. Had a couple of functions trying to do the same thing but getting compicated.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top