Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 193
Default Count and get position of spaces within a string

I have a columnn full of strings of varaible length and content which contain
0 to 4 spaces interspersed within the string
eg "1 1p 3 7c " or "2 4 1" or "1 2 x 4"
I want to extract the values between the spaces. If I know the number of
spaces and the position of each space I can use the LEFT and MID functions to
extract the values i want.
I am not fussed as to whether this is done within Excel sheet adjacent cells
or within a VBA procedure and returned to 4 adjacent cells.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Count and get position of spaces within a string

Maybe you can select the column and do
Data|text to columns
delimited by spaces

Terry wrote:

I have a columnn full of strings of varaible length and content which contain
0 to 4 spaces interspersed within the string
eg "1 1p 3 7c " or "2 4 1" or "1 2 x 4"
I want to extract the values between the spaces. If I know the number of
spaces and the position of each space I can use the LEFT and MID functions to
extract the values i want.
I am not fussed as to whether this is done within Excel sheet adjacent cells
or within a VBA procedure and returned to 4 adjacent cells.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 380
Default Count and get position of spaces within a string

Public Sub test()
Dim iLastRow As Long
Dim i As Long, j As Long
Dim ary

With ActiveSheet

iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
ary = Split(Cells(i, "A").Value, " ")
For j = LBound(ary) To UBound(ary)
Cells(i, j - LBound(ary) + 2) = ary(j)
Next j
Next i

End With

End Sub

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Terry" wrote in message
...
I have a columnn full of strings of varaible length and content which

contain
0 to 4 spaces interspersed within the string
eg "1 1p 3 7c " or "2 4 1" or "1 2 x 4"
I want to extract the values between the spaces. If I know the number of
spaces and the position of each space I can use the LEFT and MID functions

to
extract the values i want.
I am not fussed as to whether this is done within Excel sheet adjacent

cells
or within a VBA procedure and returned to 4 adjacent cells.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 193
Default Count and get position of spaces within a string

Good solution did not know about the rows.count (.end etc ) or the split
function wow thanks very much

"Bob Phillips" wrote:

Public Sub test()
Dim iLastRow As Long
Dim i As Long, j As Long
Dim ary

With ActiveSheet

iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
ary = Split(Cells(i, "A").Value, " ")
For j = LBound(ary) To UBound(ary)
Cells(i, j - LBound(ary) + 2) = ary(j)
Next j
Next i

End With

End Sub

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Terry" wrote in message
...
I have a columnn full of strings of varaible length and content which

contain
0 to 4 spaces interspersed within the string
eg "1 1p 3 7c " or "2 4 1" or "1 2 x 4"
I want to extract the values between the spaces. If I know the number of
spaces and the position of each space I can use the LEFT and MID functions

to
extract the values i want.
I am not fussed as to whether this is done within Excel sheet adjacent

cells
or within a VBA procedure and returned to 4 adjacent cells.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 193
Default Count and get position of spaces within a string

Also a good solution this is very useful as well as the solution by Bob
Phillips



"Dave Peterson" wrote:

Maybe you can select the column and do
Data|text to columns
delimited by spaces

Terry wrote:

I have a columnn full of strings of varaible length and content which contain
0 to 4 spaces interspersed within the string
eg "1 1p 3 7c " or "2 4 1" or "1 2 x 4"
I want to extract the values between the spaces. If I know the number of
spaces and the position of each space I can use the LEFT and MID functions to
extract the values i want.
I am not fussed as to whether this is done within Excel sheet adjacent cells
or within a VBA procedure and returned to 4 adjacent cells.


--

Dave Peterson

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
Find String in another string - only between spaces Nir Excel Worksheet Functions 9 November 2nd 06 11:31 AM
Value between two spaces in a String [email protected] Excel Programming 5 September 29th 06 06:52 PM
counting spaces in a string xnman Excel Programming 7 May 9th 04 03:06 PM
counting spaces in a string xnman Excel Programming 4 December 16th 03 01:36 AM
Count Spaces In A String Josh in Tampa Excel Programming 2 October 23rd 03 05:59 PM


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