Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default working with strings

Hi!
Could anybody explain me how "Split" or something similar works?
I have a string and in a loop I want to choose this string´s characters
according to index(i).
I have a problem with running the following macro:

Sub choose()

Dim myString As String
Dim StringValues
Dim i As Long

sValues = _
"A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12"

StringValues = Split(myString, ",")

For i = 0 To 12

If Cells(i + 1, "A").Value < StringValues(i) Then
Cells(i +1, "A").EntireRow.Insert
End If

Next i

End Sub

Any help would be great.

Thanks, Dan


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default working with strings

Split takes a string, and 'splits' all of its components into a array. The
string is passed as the first argument, the component is defined by the
split character, the 2nd argument.

But ... you have to pas the correct variable to it for it to work. Your
string is called sValues, but your split function is using myString. Also,
if you string has 12 values, when you loop through the array, by starting at
0, you must stop at 11 not 12. But better still, use the array's Upper
bound.

Sub Choose()
Dim sValues As String
Dim myString As String
Dim StringValues
Dim i As Long

sValues = _
"A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12"

StringValues = Split(sValues, ",")

For i = 0 To UBound(StringValues)

If Cells(i + 1, "A").Value < StringValues(i) Then
Cells(i + 1, "A").EntireRow.Insert
End If

Next i

End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"DaSo" wrote in message
...
Hi!
Could anybody explain me how "Split" or something similar works?
I have a string and in a loop I want to choose this string´s characters
according to index(i).
I have a problem with running the following macro:

Sub choose()

Dim myString As String
Dim StringValues
Dim i As Long

sValues = _
"A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12"

StringValues = Split(myString, ",")

For i = 0 To 12

If Cells(i + 1, "A").Value < StringValues(i) Then
Cells(i +1, "A").EntireRow.Insert
End If

Next i

End Sub

Any help would be great.

Thanks, Dan


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default working with strings

Hi Bob!

thanks for your tip, however when I run the macro, it gives me an error
message and says there is something wrong with "Split" function. Any
idea what could it be?

I have eventually written this macro and it works fine:

Sub Choose()

Dim i As Long
Dim j As Long

Dim table
Dim tablex
Dim nazov

table = Array("A", "B", "C", "D", "E", "F", "G", "H")
tablex = Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
"12")

For j = 0 To 7

For i = 0 To 11

If Cells(12 * j + i + 1, "A").Value < table(j) + tablex(i)
Then
Cells(12 * j + i + 1, "A").EntireRow.Insert
End If

Next i

Next j

End Sub

Regards, Dan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default working with strings

Do you have Excel 97 by any chance?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"DaSo" wrote in message
...
Hi Bob!

thanks for your tip, however when I run the macro, it gives me an error
message and says there is something wrong with "Split" function. Any
idea what could it be?

I have eventually written this macro and it works fine:

Sub Choose()

Dim i As Long
Dim j As Long

Dim table
Dim tablex
Dim nazov

table = Array("A", "B", "C", "D", "E", "F", "G", "H")
tablex = Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
"12")

For j = 0 To 7

For i = 0 To 11

If Cells(12 * j + i + 1, "A").Value < table(j) + tablex(i)
Then
Cells(12 * j + i + 1, "A").EntireRow.Insert
End If

Next i

Next j

End Sub

Regards, Dan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default working with strings

Hi Bob,

yes I have Excel 97, so I guess that´s the problem?

Dan


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default working with strings

Yes, Excel97 doesn't have the Split function. Try this

Option Explicit

Sub Choose()
Dim sValues As String
Dim myString As String
Dim StringValues
Dim i As Long

sValues = _
"A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12"

StringValues = Split(sValues, ",")

For i = 0 To UBound(StringValues)

If Cells(i + 1, "A").Value < StringValues(i) Then
Cells(i + 1, "A").EntireRow.Insert
End If

Next i

End Sub

#If VBA6 Then
#Else
'-----------------------------------------------------------------
Function Split(Text As String, _
Optional Delimiter As String = ",") As Variant
'-----------------------------------------------------------------
Dim i As Long
Dim sFormula As String
Dim aryEval
Dim aryValues

If Delimiter = vbNullChar Then
Delimiter = Chr(7)
Text = Replace(Text, vbNullChar, Delimiter)
End If
sFormula = "{""" & Application.Substitute(Text, Delimiter, """,""") &
"""}"
aryEval = Evaluate(sFormula)
ReDim aryValues(0 To UBound(aryEval) - 1)
For i = 0 To UBound(aryValues)
aryValues(i) = aryEval(i + 1)
Next

Split = aryValues

End Function
#End If



--

HTH

RP
(remove nothere from the email address if mailing direct)


"DaSo" wrote in message
...
Hi Bob,

yes I have Excel 97, so I guess that´s the problem?

Dan


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!




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 and replace numeric strings in larger text strings Mr Molio Excel Worksheet Functions 8 November 9th 11 05:17 PM
Working with Strings joe Excel Discussion (Misc queries) 2 March 8th 06 08:47 PM
How to find number of pairs of strings from list of strings? greg_overholt Excel Worksheet Functions 5 January 27th 06 10:42 PM
Working with strings Ron Rosenfeld Excel Programming 0 July 30th 03 08:34 PM
Working with strings Andrew Lenczycki Excel Programming 0 July 30th 03 04:02 PM


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