Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Multiple Deliminators


How do folks,

I have a text file with several different deliminators [ , /, TAB
SPACE & more ]. What I need to do is create column seperators betwee
these deliminators.

I know I could use "Text to columns" from the DATA menu, but I have
lot of files to work through so some VBA would be more helpful.

Anyone got any suggestions

--
Fragg

-----------------------------------------------------------------------
Fraggs's Profile: http://www.excelforum.com/member.php...nfo&userid=807
View this thread: http://www.excelforum.com/showthread.php?threadid=39291

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Multiple Deliminators

Have you tried to do a file manually and use the macro recorder to
record your steps. Than edit the code to be more generic.

--
steveB

Remove "AYN" from email to respond
"Fraggs" wrote in
message ...

How do folks,

I have a text file with several different deliminators [ , /, TAB,
SPACE & more ]. What I need to do is create column seperators between
these deliminators.

I know I could use "Text to columns" from the DATA menu, but I have a
lot of files to work through so some VBA would be more helpful.

Anyone got any suggestions ?


--
Fraggs


------------------------------------------------------------------------
Fraggs's Profile:
http://www.excelforum.com/member.php...fo&userid=8077
View this thread: http://www.excelforum.com/showthread...hreadid=392919



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Multiple Deliminators

Unfortunately the Split function will only take one delimiter but the
function I have shown below will work with any number of user
delimeters.

Option Explicit

Sub Test()

Dim sText As String
Dim vArray As Variant
Dim i As Integer

sText = "a=b+c-d"
vArray = MySplit(sText)

sText = ""
For i = 1 To UBound(vArray)
sText = sText + vArray(i - 1) + vbCrLf
Next
MsgBox sText


End Sub

Function MySplit(sBuffer As String) As Variant

Dim i As Integer
Dim j As Integer
Dim vArray As Variant

j = Len(sBuffer)
i = 1
While i < j
Select Case Mid(sBuffer, i, 1)
Case Is = "="
Mid(sBuffer, i, 1) = ","
Case Is = "+"
Mid(sBuffer, i, 1) = ","
Case Is = "-"
Mid(sBuffer, i, 1) = ","
End Select
i = i + 1
Wend

vArray = Split(sBuffer, ",")

MySplit = vArray

End Function



*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Multiple Deliminators

I think I'd just replace those characters with the delimiter I wanted:

Option Explicit
Sub Test2()

Dim sText As String
Dim vArray As Variant
Dim iCtr As Long
Dim myDelims As Variant

myDelims = Array("=", "+", "-", ";", "|") 'add as many as you need

sText = "a=b+c-d"

For iCtr = LBound(myDelims) To UBound(myDelims)
sText = Replace(sText, myDelims(iCtr), ",")
Next iCtr

vArray = Split(sText, ",")

End Sub

But I was confused by the OP's message.


Edward Ulle wrote:

Unfortunately the Split function will only take one delimiter but the
function I have shown below will work with any number of user
delimeters.

Option Explicit

Sub Test()

Dim sText As String
Dim vArray As Variant
Dim i As Integer

sText = "a=b+c-d"
vArray = MySplit(sText)

sText = ""
For i = 1 To UBound(vArray)
sText = sText + vArray(i - 1) + vbCrLf
Next
MsgBox sText


End Sub

Function MySplit(sBuffer As String) As Variant

Dim i As Integer
Dim j As Integer
Dim vArray As Variant

j = Len(sBuffer)
i = 1
While i < j
Select Case Mid(sBuffer, i, 1)
Case Is = "="
Mid(sBuffer, i, 1) = ","
Case Is = "+"
Mid(sBuffer, i, 1) = ","
Case Is = "-"
Mid(sBuffer, i, 1) = ","
End Select
i = i + 1
Wend

vArray = Split(sBuffer, ",")

MySplit = vArray

End Function

*** Sent via Developersdex http://www.developersdex.com ***


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Multiple Deliminators

Oi Fraggs,

What you can do is set up a workbook where you have the list of all your
files in a worksheet column, name and path such as "D:\myfile1" in A1,
"D:\myfile2" in A2...

Then, your macro would loop through file references until the end of the
list. Inside the loop you will open (for input access read) each source file,
and also a destination file, with the same name (for append access write),
but with the extension XLS.

Then send each line of the source file (do until eof) to a function that
will search the file for any ocurrence of the characters used as delimiters
(using ASCII code ranges like 32 to 47, or arrays with the delimiters used),
and substitute them by TABS.

The function will return the line delimited with tabs, and you will print it
to the destination file.

Then, when you open the destination file, VOILA, the fields will be already
split.

Best,

Rafael

"Fraggs" wrote:


How do folks,

I have a text file with several different deliminators [ , /, TAB,
SPACE & more ]. What I need to do is create column seperators between
these deliminators.

I know I could use "Text to columns" from the DATA menu, but I have a
lot of files to work through so some VBA would be more helpful.

Anyone got any suggestions ?


--
Fraggs


------------------------------------------------------------------------
Fraggs's Profile: http://www.excelforum.com/member.php...fo&userid=8077
View this thread: http://www.excelforum.com/showthread...hreadid=392919


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
finding multiple code dates for multiple item number kmc Excel Worksheet Functions 3 February 6th 09 10:27 PM
SUMPRODUCT, SUMIF, COUNTIF for multiple sheets for multiple criter Greg in CO[_2_] Excel Worksheet Functions 0 September 18th 08 05:51 PM
Automated multiple text files into multiple sheets in one workbook Dr Dan Excel Discussion (Misc queries) 14 November 4th 07 11:32 AM
Delete Blank Rows Code - Multiple Worksheets - Multiple Documents BenS Excel Discussion (Misc queries) 3 June 29th 07 12:20 AM
view multiple files in multiple windows on multiple screens. tcom Excel Discussion (Misc queries) 7 September 15th 05 09:35 PM


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

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

About Us

"It's about Microsoft Excel"