Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 43
Default Text-to-columns, but only 1st 2 & last delimiters

I am using delimited text-to-columns in Excel 2003. I would like to
break up a single text column into two additional text columns based
on the 1st two occurances of the space delimiter (" ") within each
cell. All other spaces should be ignored. Finally, for what remains
fo the original column, I'd like to break it into an additional column
based on the last occurance of the colon delimiter (":"), with any
other colons ignored. Is there a way to do this?

Before I imported the text into Excel, I could have made the job
easier by replacing the 1st 2 spaces, and the last colon, in the text
into a special delimiting character which occurs nowhere else, such as
"@". It would be a big step backward to go back to the external text
file because I've already done a lot of grouping of rows into an
outline structure (it's a somewhat hefty file with many levels of
groupings throughout).

Perhaps I can preserve the outline structure by re-importing the text
into adjacent columns (after injecting the unique delimiting
character)....Hmmmm.....
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 43
Default Solved: Text-to-columns, but only 1st 2 & last delimiters

On Mar 25, 1:35 pm, Paul wrote:
I am using delimited text-to-columns in Excel 2003. I would like to
break up a single text column into two additional text columns based
on the 1st two occurances of the space delimiter (" ") within each
cell. All other spaces should be ignored. Finally, for what remains
fo the original column, I'd like to break it into an additional column
based on the last occurance of the colon delimiter (":"), with any
other colons ignored. Is there a way to do this?

Before I imported the text into Excel, I could have made the job
easier by replacing the 1st 2 spaces, and the last colon, in the text
into a special delimiting character which occurs nowhere else, such as
"@". It would be a big step backward to go back to the external text
file because I've already done a lot of grouping of rows into an
outline structure (it's a somewhat hefty file with many levels of
groupings throughout).

Perhaps I can preserve the outline structure by re-importing the text
into adjacent columns (after injecting the unique delimiting
character)....Hmmmm.....


Bingo. Problem solved as described. Thanks anyway!
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Text-to-columns, but only 1st 2 & last delimiters

A macro is the best way to do this

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 3/25/2008 by Joel Warburg
'
Application.CutCopyMode = False
'
LastRow = Range("A" & Rows.Count).End(xlUp).Row

For RowCount = 1 To LastRow
data = Range("A" & RowCount)
If data < "" Then
'removes spaces
secondstr = Left(data, InStr(data, " ") - 1)
thirdstr = Mid(data, InStr(data, " ") + 1)
fourthstr = Mid(thirdstr, InStr(thirdstr, " ") + 1)
thirdstr = Left(thirdstr, InStr(thirdstr, " ") - 1)

'seperate around colon
reversestr = StrReverse(secondstr)
colon_pos = Len(secondstr) + 1 - InStr(reversestr, ":")
firststr = Left(secondstr, colon_pos - 1)
secondstr = Mid(secondstr, colon_pos + 1)

Range("A" & RowCount) = fourthstr
Range("A" & RowCount).Insert Shift:=xlToRight
Range("A" & RowCount) = thirdstr
Range("A" & RowCount).Insert Shift:=xlToRight
Range("A" & RowCount) = secondstr
Range("A" & RowCount).Insert Shift:=xlToRight
Range("A" & RowCount) = firststr
End If
Next RowCount
End Sub


"Paul" wrote:

I am using delimited text-to-columns in Excel 2003. I would like to
break up a single text column into two additional text columns based
on the 1st two occurances of the space delimiter (" ") within each
cell. All other spaces should be ignored. Finally, for what remains
fo the original column, I'd like to break it into an additional column
based on the last occurance of the colon delimiter (":"), with any
other colons ignored. Is there a way to do this?

Before I imported the text into Excel, I could have made the job
easier by replacing the 1st 2 spaces, and the last colon, in the text
into a special delimiting character which occurs nowhere else, such as
"@". It would be a big step backward to go back to the external text
file because I've already done a lot of grouping of rows into an
outline structure (it's a somewhat hefty file with many levels of
groupings throughout).

Perhaps I can preserve the outline structure by re-importing the text
into adjacent columns (after injecting the unique delimiting
character)....Hmmmm.....

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Text-to-columns, but only 1st 2 & last delimiters

You do have the option of skipping certain fieds when doing datatext to
columns.

You will most likely have to make several trips though to get the configuation
you want.


Gord Dibben MS Excel MVP

On Tue, 25 Mar 2008 10:35:20 -0700 (PDT), Paul wrote:

I am using delimited text-to-columns in Excel 2003. I would like to
break up a single text column into two additional text columns based
on the 1st two occurances of the space delimiter (" ") within each
cell. All other spaces should be ignored. Finally, for what remains
fo the original column, I'd like to break it into an additional column
based on the last occurance of the colon delimiter (":"), with any
other colons ignored. Is there a way to do this?

Before I imported the text into Excel, I could have made the job
easier by replacing the 1st 2 spaces, and the last colon, in the text
into a special delimiting character which occurs nowhere else, such as
"@". It would be a big step backward to go back to the external text
file because I've already done a lot of grouping of rows into an
outline structure (it's a somewhat hefty file with many levels of
groupings throughout).

Perhaps I can preserve the outline structure by re-importing the text
into adjacent columns (after injecting the unique delimiting
character)....Hmmmm.....


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 43
Default Text-to-columns, but only 1st 2 & last delimiters

On Mar 25, 2:18 pm, Joel wrote:
A macro is the best way to do this

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 3/25/2008 by Joel Warburg
'
Application.CutCopyMode = False
'
LastRow = Range("A" & Rows.Count).End(xlUp).Row

For RowCount = 1 To LastRow
data = Range("A" & RowCount)
If data < "" Then
'removes spaces
secondstr = Left(data, InStr(data, " ") - 1)
thirdstr = Mid(data, InStr(data, " ") + 1)
fourthstr = Mid(thirdstr, InStr(thirdstr, " ") + 1)
thirdstr = Left(thirdstr, InStr(thirdstr, " ") - 1)

'seperate around colon
reversestr = StrReverse(secondstr)
colon_pos = Len(secondstr) + 1 - InStr(reversestr, ":")
firststr = Left(secondstr, colon_pos - 1)
secondstr = Mid(secondstr, colon_pos + 1)

Range("A" & RowCount) = fourthstr
Range("A" & RowCount).Insert Shift:=xlToRight
Range("A" & RowCount) = thirdstr
Range("A" & RowCount).Insert Shift:=xlToRight
Range("A" & RowCount) = secondstr
Range("A" & RowCount).Insert Shift:=xlToRight
Range("A" & RowCount) = firststr
End If
Next RowCount
End Sub

"Paul" wrote:
I am using delimited text-to-columns in Excel 2003. I would like to
break up a single text column into two additional text columns based
on the 1st two occurances of the space delimiter (" ") within each
cell. All other spaces should be ignored. Finally, for what remains
fo the original column, I'd like to break it into an additional column
based on the last occurance of the colon delimiter (":"), with any
other colons ignored. Is there a way to do this?


Before I imported the text into Excel, I could have made the job
easier by replacing the 1st 2 spaces, and the last colon, in the text
into a special delimiting character which occurs nowhere else, such as
"@". It would be a big step backward to go back to the external text
file because I've already done a lot of grouping of rows into an
outline structure (it's a somewhat hefty file with many levels of
groupings throughout).


Perhaps I can preserve the outline structure by re-importing the text
into adjacent columns (after injecting the unique delimiting
character)....Hmmmm.....


Thanks, Joel. This will be a good way to get a trial-by-fire on VBA.
Next chance I'll have to indulge will be in 2 weeks time, but I'm glad
that your code is available for future scrutiny.


  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 43
Default Text-to-columns, but only 1st 2 & last delimiters

On Tue, 25 Mar 2008 10:35:20 -0700 (PDT), Paul
wrote:
I am using delimited text-to-columns in Excel 2003. I would
like to break up a single text column into two additional text
columns based on the 1st two occurances of the space delimiter
(" ") within each cell. All other spaces should be ignored.
Finally, for what remains fo the original column, I'd like to
break it into an additional column based on the last occurance
of the colon delimiter (":"), with any other colons ignored.
Is there a way to do this?

Before I imported the text into Excel, I could have made the
job easier by replacing the 1st 2 spaces, and the last colon,
in the text into a special delimiting character which occurs
nowhere else, such as "@". It would be a big step backward to
go back to the external text file because I've already done a
lot of grouping of rows into an outline structure (it's a
somewhat hefty file with many levels of groupings throughout).

Perhaps I can preserve the outline structure by re-importing
the text into adjacent columns (after injecting the unique
delimiting character)....Hmmmm.....


On Mar 25, 2:25 pm, Gord Dibben <gorddibbATshawDOTca wrote:
You do have the option of skipping certain fieds when doing
datatext to columns.

You will most likely have to make several trips though to get
the configuation you want.


Thanks, Gord. I've managed to finangle the text code with unique
delimiters where needed, and pull it into Excel using one pass
while still preserving the outline structure. I may have future
reason yet revisit this ability to skip certain fields upon
importing.
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
How to Export as text file with NO delimiters or modifications? MojoNixon Excel Discussion (Misc queries) 5 August 15th 06 09:37 PM
Importing text file with no line delimiters mikewilsonuk Excel Discussion (Misc queries) 4 June 15th 06 06:47 AM
Export (or save as) .csv with text delimiters CarolineP Excel Discussion (Misc queries) 2 February 17th 05 02:25 AM
How To Import Text File With No Delimiters? Sam Excel Discussion (Misc queries) 1 February 8th 05 05:54 PM
How do I get carriage returns to not be row delimiters in text fi. RV Excel Discussion (Misc queries) 1 December 16th 04 11:47 PM


All times are GMT +1. The time now is 08:28 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"