Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
DZ DZ is offline
external usenet poster
 
Posts: 29
Default looping through comma delimited text

Hi

I need to do something with a comma delimited block of text.

.....like
text , text, text, etc

Can someone help me write a loop to loop through each block of text between
commas?

Thanks alot for any help


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default looping through comma delimited text

Consider this...

Dim X As Long
Dim BlockOfText As String
Dim Fields() As String
BlockOfText = "text1, text2, text3, etc."
' The next statement assumes a comma followed
' by a space, as shown, is the delimiting the text
Fields = Split(BlockOfText, ", ")
' The zero-based Fields array now holds
' each text sub-string in its elements...
For X = 0 To UBound(Fields)
Debug.Print Fields(X)
Next

Rick


"DZ" wrote in message
...
Hi

I need to do something with a comma delimited block of text.

....like
text , text, text, etc

Can someone help me write a loop to loop through each block of text
between
commas?

Thanks alot for any help



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default looping through comma delimited text

Here is some code you might use

Sub GetCSVData()

Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Const Delimiter = ","
Set fsread = CreateObject("Scripting.FileSystemObject")

'default folder
Folder = "C:\temp\test"
ChDir (Folder)

FName = Application.GetOpenFilename("CSV (*.csv),*.csv")


RowCount = LastRow + 1
If FName < "" Then
'open files
Set fread = fsread.GetFile(FName)
Set tsread = fread.OpenAsTextStream(ForReading, TristateUseDefault)

Do While tsread.atendofstream = False

InputLine = tsread.ReadLine

'extract comma seperated data
ColumnCount = 1
Do While InputLine < ""
DelimiterPosition = InStr(InputLine, Delimiter)
If DelimiterPosition 0 Then
Data = Trim(Left(InputLine, DelimiterPosition - 1))
InputLine = Mid(InputLine, DelimiterPosition + 1)
Else
Data = Trim(InputLine)
InputLine = ""
End If

Cells(RowCount, ColumnCount) = Data
ColumnCount = ColumnCount + 1
Loop
RowCount = RowCount + 1
Loop

tsread.Close
End If
End Sub


"DZ" wrote:

Hi

I need to do something with a comma delimited block of text.

....like
text , text, text, etc

Can someone help me write a loop to loop through each block of text between
commas?

Thanks alot for any help


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using comma inside the comma delimited text in Data Validation/Sou LasseH Excel Programming 5 December 14th 07 04:09 AM
Converting Tab Delimited Text File to A Comma Delimited Text File Dave Peterson Excel Programming 0 June 13th 07 03:13 PM
Import comma delimited text Lin Excel Discussion (Misc queries) 3 July 28th 06 04:07 PM
Comma Delimited Text File Issue solomon_monkey Excel Programming 12 December 22nd 04 09:51 PM
Comma delimited text to columns Ann Vlna Excel Programming 4 June 15th 04 01:07 PM


All times are GMT +1. The time now is 04:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"