Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Splitting String into Consitiutent Parts including spaces characte

I have a string which has had elements removed creating variable spaces (have
shown spaces with dashes):

-$A7-$B$11-----$I$2-$I$6--I6--------1-3-3-$I$6-K$3

I want to be able to split this string into its consituent parts (spaces
included). I am not sure if using the split function will work as I am not
using the spaces as delimiters. I want to be able to split as follows:

Substring1 = -
Substring2 = $A7
Substring3 = -
Substring4 = B$11
Substring5 = -
Substring6 = -
Substring7 = -
Substring8 = -
Substring9 = -
Substring9 = $I$2
etc......

Can anyone tell me what other options I have for this besides Split? Or if
Split can in fact do this.

Thanks




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Splitting String into Consitiutent Parts including spaces characte

Have you tried it? I copied your string to the immediate pane and replaced
"-" with " " and tried a = split(z, " ") and the results appear to be what
you specified (except array is starting at 0 instead of 1.)

--
Kevin Vaughn


"ExcelMonkey" wrote:

I have a string which has had elements removed creating variable spaces (have
shown spaces with dashes):

-$A7-$B$11-----$I$2-$I$6--I6--------1-3-3-$I$6-K$3

I want to be able to split this string into its consituent parts (spaces
included). I am not sure if using the split function will work as I am not
using the spaces as delimiters. I want to be able to split as follows:

Substring1 = -
Substring2 = $A7
Substring3 = -
Substring4 = B$11
Substring5 = -
Substring6 = -
Substring7 = -
Substring8 = -
Substring9 = -
Substring9 = $I$2
etc......

Can anyone tell me what other options I have for this besides Split? Or if
Split can in fact do this.

Thanks




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Splitting String into Consitiutent Parts including spaces characte

Hi ExcelMonkey,

Try:
'=============
Public Sub Tester()
Dim sStr As String
Dim arr As Variant
Dim i As Long, j As Long

sStr = _
"-$A7-$B$11-----$I$2-$I$6--I6--------1-3-3-$I$6-K$3"

arr = Split(Replace(sStr, "-", "#-#"), "#")

For i = LBound(arr) To UBound(arr)
If arr(i) < vbNullString Then
j = j + 1
Cells(j, "A").Value = arr(i)
End If
Next i
End Sub
'<<=============

---
Regards,
Norman


"ExcelMonkey" wrote in message
...
I have a string which has had elements removed creating variable spaces
(have
shown spaces with dashes):

-$A7-$B$11-----$I$2-$I$6--I6--------1-3-3-$I$6-K$3

I want to be able to split this string into its consituent parts (spaces
included). I am not sure if using the split function will work as I am not
using the spaces as delimiters. I want to be able to split as follows:

Substring1 = -
Substring2 = $A7
Substring3 = -
Substring4 = B$11
Substring5 = -
Substring6 = -
Substring7 = -
Substring8 = -
Substring9 = -
Substring9 = $I$2
etc......

Can anyone tell me what other options I have for this besides Split? Or
if
Split can in fact do this.

Thanks






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Splitting String into Consitiutent Parts including spaces characte

On Tue, 7 Feb 2006 15:55:27 -0800, "ExcelMonkey"
wrote:

I have a string which has had elements removed creating variable spaces (have
shown spaces with dashes):

-$A7-$B$11-----$I$2-$I$6--I6--------1-3-3-$I$6-K$3

I want to be able to split this string into its consituent parts (spaces
included). I am not sure if using the split function will work as I am not
using the spaces as delimiters. I want to be able to split as follows:

Substring1 = -
Substring2 = $A7
Substring3 = -
Substring4 = B$11
Substring5 = -
Substring6 = -
Substring7 = -
Substring8 = -
Substring9 = -
Substring9 = $I$2
etc......

Can anyone tell me what other options I have for this besides Split? Or if
Split can in fact do this.

Thanks




If you just use Split, I believe that the elements of the array that are
<space's will be null strings. So if you want <space's there, you could
substitute.

For example:

=======================
a = Split(your_string)
For i = 0 To UBound(a)
If a(i) = "" Then a(i) = " "
Next i
======================


--ron
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Splitting String into Consitiutent Parts including spaces characte

ExcelMonkey,
I assume each "-" or range/number is an element, all of which need to be
preserved, for a total of 32 elements.

Would "-$I$2-$I$6I6-" be a valid input ? Note 3 non-space values; $I$2,
$I$6I ,6.
Or "-3-3$I$6-" ?

NickHK

"ExcelMonkey" wrote in message
...
I have a string which has had elements removed creating variable spaces

(have
shown spaces with dashes):

-$A7-$B$11-----$I$2-$I$6--I6--------1-3-3-$I$6-K$3

I want to be able to split this string into its consituent parts (spaces
included). I am not sure if using the split function will work as I am not
using the spaces as delimiters. I want to be able to split as follows:

Substring1 = -
Substring2 = $A7
Substring3 = -
Substring4 = B$11
Substring5 = -
Substring6 = -
Substring7 = -
Substring8 = -
Substring9 = -
Substring9 = $I$2
etc......

Can anyone tell me what other options I have for this besides Split? Or

if
Split can in fact do this.

Thanks








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Splitting String into Consitiutent Parts including spaces char

So I am confused. I effectively have this string:

$A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3

It clearly has spaces in it at variable lenghts. I want to split it up into
segments. Then I want to step throught the array, if the substring is a cell
address, I want to offset by 1 column if its not a cell address (a number or
a space) I want to make it a space. The problem I am having is that when I
step throught the array, I am getting space values for spaces that are "" and
" ". I am not sure why this is. My goal was to split the string by each
into its consitutent substrings including spaces (i.e 0 = " ", 1 = $A7, 2 =
$B$11, 3 = " " etc). The code fails on the line Set r = Range(Suspectedrng)
because some of the array elements return values of "". Why is this?

Sub Thing ()
Dim CurrentFormula As String
Dim SuspectedrngArray As Variant
Dim X As Integer
Dim r As Range
Dim RevisedRngRight As String
Dim PassedRange As String

CurrentFormula = $A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3
SuspectedrngArray = Split(Replace(CurrentFormula, " ", "# #"), "#")

For X = LBound(SuspectedrngArray) To UBound(SuspectedrngArray)
Suspectedrng = SuspectedrngArray(X)
'If cell address then offset otherwise, make " "
If Not Suspectedrng = " " And Not
Application.WorksheetFunction.IsNumber(Suspectedrn g) Then
Set r = Range(Suspectedrng)
RevisedRngRight = r.Offset(0, 1).Address
ElseIf RevisedRngRight = " " Then
RevisedRngRight = " "
Else
RevisedRngRight = Suspectedrng
End If
PassedRange = PassedRange & RevisedRngRight
Next

End Sub

"Norman Jones" wrote:

Hi ExcelMonkey,

Try:
'=============
Public Sub Tester()
Dim sStr As String
Dim arr As Variant
Dim i As Long, j As Long

sStr = _
"-$A7-$B$11-----$I$2-$I$6--I6--------1-3-3-$I$6-K$3"

arr = Split(Replace(sStr, "-", "#-#"), "#")

For i = LBound(arr) To UBound(arr)
If arr(i) < vbNullString Then
j = j + 1
Cells(j, "A").Value = arr(i)
End If
Next i
End Sub
'<<=============

---
Regards,
Norman


"ExcelMonkey" wrote in message
...
I have a string which has had elements removed creating variable spaces
(have
shown spaces with dashes):

-$A7-$B$11-----$I$2-$I$6--I6--------1-3-3-$I$6-K$3

I want to be able to split this string into its consituent parts (spaces
included). I am not sure if using the split function will work as I am not
using the spaces as delimiters. I want to be able to split as follows:

Substring1 = -
Substring2 = $A7
Substring3 = -
Substring4 = B$11
Substring5 = -
Substring6 = -
Substring7 = -
Substring8 = -
Substring9 = -
Substring9 = $I$2
etc......

Can anyone tell me what other options I have for this besides Split? Or
if
Split can in fact do this.

Thanks







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Splitting String into Consitiutent Parts including spaces char

Hi ExcelMonkey,

Try replacing:

If Not Suspectedrng = " " And Not
Application.WorksheetFunction.IsNumber(Suspectedrn g) Then


with:

If Not Suspectedrng = " " _
And Not Suspectedrng = vbNullString _
And Not Application.IsNumber(Suspectedrng) Then


---
Regards,
Norman


"ExcelMonkey" wrote in message
...
So I am confused. I effectively have this string:

$A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3

It clearly has spaces in it at variable lenghts. I want to split it up
into
segments. Then I want to step throught the array, if the substring is a
cell
address, I want to offset by 1 column if its not a cell address (a number
or
a space) I want to make it a space. The problem I am having is that when
I
step throught the array, I am getting space values for spaces that are ""
and
" ". I am not sure why this is. My goal was to split the string by each
into its consitutent substrings including spaces (i.e 0 = " ", 1 = $A7, 2
=
$B$11, 3 = " " etc). The code fails on the line Set r =
Range(Suspectedrng)
because some of the array elements return values of "". Why is this?

Sub Thing ()
Dim CurrentFormula As String
Dim SuspectedrngArray As Variant
Dim X As Integer
Dim r As Range
Dim RevisedRngRight As String
Dim PassedRange As String

CurrentFormula = $A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3
SuspectedrngArray = Split(Replace(CurrentFormula, " ", "# #"), "#")

For X = LBound(SuspectedrngArray) To UBound(SuspectedrngArray)
Suspectedrng = SuspectedrngArray(X)
'If cell address then offset otherwise, make " "
If Not Suspectedrng = " " And Not
Application.WorksheetFunction.IsNumber(Suspectedrn g) Then
Set r = Range(Suspectedrng)
RevisedRngRight = r.Offset(0, 1).Address
ElseIf RevisedRngRight = " " Then
RevisedRngRight = " "
Else
RevisedRngRight = Suspectedrng
End If
PassedRange = PassedRange & RevisedRngRight
Next

End Sub



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Splitting String into Consitiutent Parts including spaces char

The back end of the array has numbers(1,3,3):
$A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3

As these are text characters, they do not return TRUE in the:
ISNUMBER("1"):

?Application.WorksheetFunction.IsNumber("1")
False

vs.

?Application.WorksheetFunction.IsNumber(1)
True

Is there a function I can wrap around these to turn them into numbers?

Thanks

EM


"Norman Jones" wrote:

Hi ExcelMonkey,

Try replacing:

If Not Suspectedrng = " " And Not
Application.WorksheetFunction.IsNumber(Suspectedrn g) Then


with:

If Not Suspectedrng = " " _
And Not Suspectedrng = vbNullString _
And Not Application.IsNumber(Suspectedrng) Then


---
Regards,
Norman


"ExcelMonkey" wrote in message
...
So I am confused. I effectively have this string:

$A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3

It clearly has spaces in it at variable lenghts. I want to split it up
into
segments. Then I want to step throught the array, if the substring is a
cell
address, I want to offset by 1 column if its not a cell address (a number
or
a space) I want to make it a space. The problem I am having is that when
I
step throught the array, I am getting space values for spaces that are ""
and
" ". I am not sure why this is. My goal was to split the string by each
into its consitutent substrings including spaces (i.e 0 = " ", 1 = $A7, 2
=
$B$11, 3 = " " etc). The code fails on the line Set r =
Range(Suspectedrng)
because some of the array elements return values of "". Why is this?

Sub Thing ()
Dim CurrentFormula As String
Dim SuspectedrngArray As Variant
Dim X As Integer
Dim r As Range
Dim RevisedRngRight As String
Dim PassedRange As String

CurrentFormula = $A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3
SuspectedrngArray = Split(Replace(CurrentFormula, " ", "# #"), "#")

For X = LBound(SuspectedrngArray) To UBound(SuspectedrngArray)
Suspectedrng = SuspectedrngArray(X)
'If cell address then offset otherwise, make " "
If Not Suspectedrng = " " And Not
Application.WorksheetFunction.IsNumber(Suspectedrn g) Then
Set r = Range(Suspectedrng)
RevisedRngRight = r.Offset(0, 1).Address
ElseIf RevisedRngRight = " " Then
RevisedRngRight = " "
Else
RevisedRngRight = Suspectedrng
End If
PassedRange = PassedRange & RevisedRngRight
Next

End Sub




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Splitting String into Consitiutent Parts including spaces char

I can conver the text value of "1" to a number by using the Cdbl() function
doing the following:

?Application.WorksheetFunction.IsNumber(Cdbl("1"))
True

However this may need som error handling as the following will give me an
error:
?Application.WorksheetFunction.IsNumber(Cdbl("$A$1 "))


"ExcelMonkey" wrote:

The back end of the array has numbers(1,3,3):
$A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3

As these are text characters, they do not return TRUE in the:
ISNUMBER("1"):

?Application.WorksheetFunction.IsNumber("1")
False

vs.

?Application.WorksheetFunction.IsNumber(1)
True

Is there a function I can wrap around these to turn them into numbers?

Thanks

EM


"Norman Jones" wrote:

Hi ExcelMonkey,

Try replacing:

If Not Suspectedrng = " " And Not
Application.WorksheetFunction.IsNumber(Suspectedrn g) Then


with:

If Not Suspectedrng = " " _
And Not Suspectedrng = vbNullString _
And Not Application.IsNumber(Suspectedrng) Then


---
Regards,
Norman


"ExcelMonkey" wrote in message
...
So I am confused. I effectively have this string:

$A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3

It clearly has spaces in it at variable lenghts. I want to split it up
into
segments. Then I want to step throught the array, if the substring is a
cell
address, I want to offset by 1 column if its not a cell address (a number
or
a space) I want to make it a space. The problem I am having is that when
I
step throught the array, I am getting space values for spaces that are ""
and
" ". I am not sure why this is. My goal was to split the string by each
into its consitutent substrings including spaces (i.e 0 = " ", 1 = $A7, 2
=
$B$11, 3 = " " etc). The code fails on the line Set r =
Range(Suspectedrng)
because some of the array elements return values of "". Why is this?

Sub Thing ()
Dim CurrentFormula As String
Dim SuspectedrngArray As Variant
Dim X As Integer
Dim r As Range
Dim RevisedRngRight As String
Dim PassedRange As String

CurrentFormula = $A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3
SuspectedrngArray = Split(Replace(CurrentFormula, " ", "# #"), "#")

For X = LBound(SuspectedrngArray) To UBound(SuspectedrngArray)
Suspectedrng = SuspectedrngArray(X)
'If cell address then offset otherwise, make " "
If Not Suspectedrng = " " And Not
Application.WorksheetFunction.IsNumber(Suspectedrn g) Then
Set r = Range(Suspectedrng)
RevisedRngRight = r.Offset(0, 1).Address
ElseIf RevisedRngRight = " " Then
RevisedRngRight = " "
Else
RevisedRngRight = Suspectedrng
End If
PassedRange = PassedRange & RevisedRngRight
Next

End Sub




  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Splitting String into Consitiutent Parts including spaces char

Hi ExcelMonkey

?Application.WorksheetFunction.IsNumber(CLng("1"))
True


---
Regards,
Norman



"ExcelMonkey" wrote in message
...
The back end of the array has numbers(1,3,3):
$A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3

As these are text characters, they do not return TRUE in the:
ISNUMBER("1"):

?Application.WorksheetFunction.IsNumber("1")
False

vs.

?Application.WorksheetFunction.IsNumber(1)
True

Is there a function I can wrap around these to turn them into numbers?

Thanks

EM


"Norman Jones" wrote:

Hi ExcelMonkey,

Try replacing:

If Not Suspectedrng = " " And Not
Application.WorksheetFunction.IsNumber(Suspectedrn g) Then


with:

If Not Suspectedrng = " " _
And Not Suspectedrng = vbNullString _
And Not Application.IsNumber(Suspectedrng) Then


---
Regards,
Norman


"ExcelMonkey" wrote in message
...
So I am confused. I effectively have this string:

$A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3

It clearly has spaces in it at variable lenghts. I want to split it up
into
segments. Then I want to step throught the array, if the substring is
a
cell
address, I want to offset by 1 column if its not a cell address (a
number
or
a space) I want to make it a space. The problem I am having is that
when
I
step throught the array, I am getting space values for spaces that are
""
and
" ". I am not sure why this is. My goal was to split the string by
each
into its consitutent substrings including spaces (i.e 0 = " ", 1 = $A7,
2
=
$B$11, 3 = " " etc). The code fails on the line Set r =
Range(Suspectedrng)
because some of the array elements return values of "". Why is this?

Sub Thing ()
Dim CurrentFormula As String
Dim SuspectedrngArray As Variant
Dim X As Integer
Dim r As Range
Dim RevisedRngRight As String
Dim PassedRange As String

CurrentFormula = $A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3
SuspectedrngArray = Split(Replace(CurrentFormula, " ", "# #"), "#")

For X = LBound(SuspectedrngArray) To UBound(SuspectedrngArray)
Suspectedrng = SuspectedrngArray(X)
'If cell address then offset otherwise, make " "
If Not Suspectedrng = " " And Not
Application.WorksheetFunction.IsNumber(Suspectedrn g) Then
Set r = Range(Suspectedrng)
RevisedRngRight = r.Offset(0, 1).Address
ElseIf RevisedRngRight = " " Then
RevisedRngRight = " "
Else
RevisedRngRight = Suspectedrng
End If
PassedRange = PassedRange & RevisedRngRight
Next

End Sub








  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Splitting String into Consitiutent Parts including spaces char

Sorry I have tried to post this 3 times now but the site keeps crashing. How
do I implemen the error handling need for non numbers (range addresses and
spaces):

?Application.WorksheetFunction.IsNumber(CLng("$A$1 "))
?Application.WorksheetFunction.IsNumber(CLng(" "))

Thanks

EM

"Norman Jones" wrote:

Hi ExcelMonkey

?Application.WorksheetFunction.IsNumber(CLng("1"))
True


---
Regards,
Norman



"ExcelMonkey" wrote in message
...
The back end of the array has numbers(1,3,3):
$A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3

As these are text characters, they do not return TRUE in the:
ISNUMBER("1"):

?Application.WorksheetFunction.IsNumber("1")
False

vs.

?Application.WorksheetFunction.IsNumber(1)
True

Is there a function I can wrap around these to turn them into numbers?

Thanks

EM


"Norman Jones" wrote:

Hi ExcelMonkey,

Try replacing:

If Not Suspectedrng = " " And Not
Application.WorksheetFunction.IsNumber(Suspectedrn g) Then

with:

If Not Suspectedrng = " " _
And Not Suspectedrng = vbNullString _
And Not Application.IsNumber(Suspectedrng) Then


---
Regards,
Norman


"ExcelMonkey" wrote in message
...
So I am confused. I effectively have this string:

$A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3

It clearly has spaces in it at variable lenghts. I want to split it up
into
segments. Then I want to step throught the array, if the substring is
a
cell
address, I want to offset by 1 column if its not a cell address (a
number
or
a space) I want to make it a space. The problem I am having is that
when
I
step throught the array, I am getting space values for spaces that are
""
and
" ". I am not sure why this is. My goal was to split the string by
each
into its consitutent substrings including spaces (i.e 0 = " ", 1 = $A7,
2
=
$B$11, 3 = " " etc). The code fails on the line Set r =
Range(Suspectedrng)
because some of the array elements return values of "". Why is this?

Sub Thing ()
Dim CurrentFormula As String
Dim SuspectedrngArray As Variant
Dim X As Integer
Dim r As Range
Dim RevisedRngRight As String
Dim PassedRange As String

CurrentFormula = $A7 $B$11 $I$2 $I$6 I6 1 3 3 $I$6 K$3
SuspectedrngArray = Split(Replace(CurrentFormula, " ", "# #"), "#")

For X = LBound(SuspectedrngArray) To UBound(SuspectedrngArray)
Suspectedrng = SuspectedrngArray(X)
'If cell address then offset otherwise, make " "
If Not Suspectedrng = " " And Not
Application.WorksheetFunction.IsNumber(Suspectedrn g) Then
Set r = Range(Suspectedrng)
RevisedRngRight = r.Offset(0, 1).Address
ElseIf RevisedRngRight = " " Then
RevisedRngRight = " "
Else
RevisedRngRight = Suspectedrng
End If
PassedRange = PassedRange & RevisedRngRight
Next

End Sub







  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Splitting String into Consitiutent Parts including spaces char

Hi ExcelMonkey,

Try instead:

If Not Suspectedrng = " " _
And Not Suspectedrng = vbNullString _
And NotIsNumeric(Suspectedrng) Then


?Application.WorksheetFunction.IsNumber("1")
False

?Isnumeric("1")
True

---
Regards,
Norman



"ExcelMonkey" wrote in message
...
Sorry I have tried to post this 3 times now but the site keeps crashing.
How
do I implemen the error handling need for non numbers (range addresses and
spaces):

?Application.WorksheetFunction.IsNumber(CLng("$A$1 "))
?Application.WorksheetFunction.IsNumber(CLng(" "))

Thanks

EM



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 up data by spaces Nick C Excel Discussion (Misc queries) 2 June 12th 08 01:24 AM
Splitting a file with lookup functions into smaller parts Dave McD Excel Worksheet Functions 3 October 25th 07 12:04 AM
Including spaces in filters steev_jd Excel Discussion (Misc queries) 4 August 10th 06 02:43 PM
COUNT THE NUMBER OF LETTERS INCLUDING SPACES IN A CELL? zurafz6 Excel Worksheet Functions 7 March 6th 06 07:53 AM
Painting my kitchen exposed parts (including ceiling) David Smithz Excel Discussion (Misc queries) 2 March 4th 06 12:31 AM


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