Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 150
Default Splitting a string into columns

Hi,

A cell has the following string:
1-5 3-4 12-2 1-3 5
ie. pairs of numbers separated by a hyphen and an odd lone number at
the end of the string

This needs to be converted into columns and rows as follows:
1 5
3 4
12 2
1 3 5

Each hyphenated pair into two columns in a row and the odd lone number
in a third column in the last row.

Thanks in advance for the help.

Regards,
Raj
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Splitting a string into columns

Raj,

What are the number pairs separated by? In your post it appears to be
multiple spaces.

Where is the output to appear relative to the cell containing the original
string? For example, should the current cell with the string be the upper
left cell of the range created?

Is it always going to be four number pairs and an odd lone number or might
there be more pairs?


Steve Yandl



"Raj" wrote in message
...
Hi,

A cell has the following string:
1-5 3-4 12-2 1-3 5
ie. pairs of numbers separated by a hyphen and an odd lone number at
the end of the string

This needs to be converted into columns and rows as follows:
1 5
3 4
12 2
1 3 5

Each hyphenated pair into two columns in a row and the odd lone number
in a third column in the last row.

Thanks in advance for the help.

Regards,
Raj


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 150
Default Splitting a string into columns

The number pairs are separated by one or more spaces.

The current cell with the string should be the upper left cell of the
range.

The number of pairs in a cell are not fixed: they can vary from one to
several.

Thanks,

Regards,
Raj





On May 1, 4:33*am, "Steve Yandl" wrote:
Raj,

What are the number pairs separated by? *In your post it appears to be
multiple spaces.

Where is the output to appear relative to the cell containing the original
string? *For example, should the current cell with the string be the upper
left cell of the range created?

Is it always going to be four number pairs and an odd lone number or might
there be more pairs?

Steve Yandl

"Raj" wrote in message

...

Hi,


A cell has *the following string:
* 1-5 * * * 3-4 * * * 12-2 * * * 1-3 5
ie. pairs of numbers separated by a hyphen and an odd lone number at
the end of the string


This needs to be converted into columns and rows as follows:
1 * * *5
3 * * *4
12 * * 2
1 * * *3 * * *5


Each hyphenated pair into two columns in a row and the odd lone number
in a third column in the last row.


Thanks in advance for the help.


Regards,
Raj


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 464
Default Splitting a string into columns

Data Text to columns...



--
Regards
Dave Hawley
www.ozgrid.com
"Raj" wrote in message
...
Hi,

A cell has the following string:
1-5 3-4 12-2 1-3 5
ie. pairs of numbers separated by a hyphen and an odd lone number at
the end of the string

This needs to be converted into columns and rows as follows:
1 5
3 4
12 2
1 3 5

Each hyphenated pair into two columns in a row and the odd lone number
in a third column in the last row.

Thanks in advance for the help.

Regards,
Raj


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Splitting a string into columns

Give this macro a try (simply select the cell with your text string
first)...

Sub DistributeNumbers()
Dim X As Long, CellText As String, Parts() As String
CellText = WorksheetFunction.Trim(Selection.Value)
Parts = Split(CellText)
For X = 0 To UBound(Parts) - 1
Selection.Offset(X, 0).Value = Split(Parts(X), "-")(0)
Selection.Offset(X, 1).Value = Split(Parts(X), "-")(1)
Next
Selection.Offset(UBound(Parts) - 1, 2).Value = Parts(UBound(Parts))
End Sub

--
Rick (MVP - Excel)



"Raj" wrote in message
...
Hi,

A cell has the following string:
1-5 3-4 12-2 1-3 5
ie. pairs of numbers separated by a hyphen and an odd lone number at
the end of the string

This needs to be converted into columns and rows as follows:
1 5
3 4
12 2
1 3 5

Each hyphenated pair into two columns in a row and the odd lone number
in a third column in the last row.

Thanks in advance for the help.

Regards,
Raj




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 150
Default Splitting a string into columns

Thanks a ton, Rick, Works like magic.

Regards,
Raj


On May 1, 8:01*am, "Rick Rothstein"
wrote:
Give this macro a try (simply select the cell with your text string
first)...

Sub DistributeNumbers()
* Dim X As Long, CellText As String, Parts() As String
* CellText = WorksheetFunction.Trim(Selection.Value)
* Parts = Split(CellText)
* For X = 0 To UBound(Parts) - 1
* * Selection.Offset(X, 0).Value = Split(Parts(X), "-")(0)
* * Selection.Offset(X, 1).Value = Split(Parts(X), "-")(1)
* Next
* Selection.Offset(UBound(Parts) - 1, 2).Value = Parts(UBound(Parts))
End Sub

--
Rick (MVP - Excel)

"Raj" wrote in message

...

Hi,


A cell has *the following string:
* 1-5 * * * 3-4 * * * 12-2 * * * 1-3 5
ie. pairs of numbers separated by a hyphen and an odd lone number at
the end of the string


This needs to be converted into columns and rows as follows:
1 * * *5
3 * * *4
12 * * 2
1 * * *3 * * *5


Each hyphenated pair into two columns in a row and the odd lone number
in a third column in the last row.


Thanks in advance for the help.


Regards,
Raj


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
splitting a string roc616 Excel Programming 5 June 23rd 08 06:48 PM
Splitting a text string into string and number mcambrose Excel Discussion (Misc queries) 4 February 21st 06 03:47 PM
splitting string in 2 parts ashishprem[_4_] Excel Programming 2 February 14th 06 01:30 PM
Splitting a String AMK4[_42_] Excel Programming 8 February 14th 06 12:12 AM
Splitting Character String mcertini Excel Worksheet Functions 2 September 12th 05 09:41 AM


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

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"