PC Review


Reply
Thread Tools Rate Thread

Count and get position of spaces within a string

 
 
=?Utf-8?B?VGVycnk=?=
Guest
Posts: n/a
 
      23rd Oct 2006
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.

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      23rd Oct 2006
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 With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      23rd Oct 2006
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" <(E-Mail Removed)> wrote in message
news:F61E7D66-E5F4-477B-AF50-(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
=?Utf-8?B?VGVycnk=?=
Guest
Posts: n/a
 
      24th Oct 2006
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" <(E-Mail Removed)> wrote in message
> news:F61E7D66-E5F4-477B-AF50-(E-Mail Removed)...
> > 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.
> >

>
>
>

 
Reply With Quote
 
=?Utf-8?B?VGVycnk=?=
Guest
Posts: n/a
 
      24th Oct 2006
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count how many spaces =?Utf-8?B?Qm9ubmll?= Microsoft Access 13 31st Oct 2007 07:19 PM
Find String in another string - only between spaces =?Utf-8?B?Tmly?= Microsoft Excel Worksheet Functions 9 2nd Nov 2006 11:31 AM
Tough One, trying to count occurences of string based on string in separate column Rick Microsoft Excel New Users 3 28th Feb 2004 02:10 AM
Count Spaces In A String Josh in Tampa Microsoft Excel Programming 2 23rd Oct 2003 05:59 PM
Count Number of Spaces Within String Larry R Harrison Jr Microsoft Access Form Coding 8 22nd Aug 2003 11:00 PM


Features
 

Advertising
 

Newsgroups
 


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