I have this string, as String:
STRINGA=ciao0, ciao1,....,ciao99"
Ho to split with comma separated ad looping, item?
split string and looping item
-
- 3StarLounger
- Posts: 264
- Joined: 04 Oct 2017, 15:47
Re: split string and looping item
May Be!
Code: Select all
Sub splitpp()
f = Cells(Rows.Count, 1).End(3).Row
For i = 2 To f
arr = split(Range("a" & i), ",")
For Each cell In arr
k = k + 1
Cells(k, 2) = cell
Next cell
Next i
End Sub
-
- Administrator
- Posts: 78478
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: split string and looping item
Or
Code: Select all
Dim arr() As String
Dim i As Long
arr = Split(STRINGA, ", ")
For i = 0 To UBound(arr)
' Do something with arr(i)
Next i
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4355
- Joined: 26 Apr 2010, 17:36
Re: split string and looping item
HansV wrote: ↑12 Feb 2021, 08:02Or
Code: Select all
Dim arr() As String Dim i As Long arr = Split(STRINGA, ", ") For i = 0 To UBound(arr) ' Do something with arr(i) Next i
-
- Administrator
- Posts: 12604
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: split string and looping item
I posted a reply very similar to the one that Hans posted, but it seems to have got lost in the recent hiatus with the lounge database. The one time I beat Hans to a response this year too!
StuartR
-
- Administrator
- Posts: 78478
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- BronzeLounger
- Posts: 1499
- Joined: 28 Feb 2015, 13:11
- Location: Hof, Bayern, Germany
Re: split string and looping item
@Stuart,
Your post did appear. http://i.imgur.com/7itA5V5.jpg http://i.imgur.com/1opb53h.jpg
I think it may have been the last thing posted before the database problem. My guess is that the combined effect of Hans not appearing first and your Jacket appearing where his shoes were expected, was too much of a shock, and that crashed the system
:)
_.____________________________________
Here is another one to compliment the other 2(3) from adeel1 , Hans ( Stuart )
http://i.imgur.com/ePvdF2j.jpg
Your post did appear. http://i.imgur.com/7itA5V5.jpg http://i.imgur.com/1opb53h.jpg
I think it may have been the last thing posted before the database problem. My guess is that the combined effect of Hans not appearing first and your Jacket appearing where his shoes were expected, was too much of a shock, and that crashed the system
:)
_.____________________________________
Here is another one to compliment the other 2(3) from adeel1 , Hans ( Stuart )
Code: Select all
Sub SplitStringOutHorizontal() ' https://eileenslounge.com/viewtopic.php?f=30&t=36128
Dim STRINGA As String
Let STRINGA = "ciao0,ciao1,ciao2"
Dim Arr() As String: Let Arr() = Split(STRINGA, ",", -1, vbBinaryCompare)
Dim Ws As Worksheet: Set Ws = ActiveSheet
Let Ws.Range(Ws.Cells(1, 1), Ws.Cells(1, UBound(Arr()) + 1)).Value = Arr()
End Sub
Sub SplitStringOutVertical()
Dim STRINGA As String
Let STRINGA = "ciao0,ciao1,ciao2"
Dim Arr() As String: Let Arr() = Split(STRINGA, ",", -1, vbBinaryCompare)
Dim Ws As Worksheet: Set Ws = ActiveSheet
Let Ws.Range(Ws.Cells(1, 1), Ws.Cells(UBound(Arr()) + 1, 1)).Value = Application.Index(Arr(), Evaluate("=row(1:" & UBound(Arr()) + 1 & ")/row(1:" & UBound(Arr()) + 1 & ")"), Evaluate("=row(1:" & UBound(Arr()) + 1 & ")"))
End Sub
You do not have the required permissions to view the files attached to this post.
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also
You can find me at DocAElstein also
-
- Administrator
- Posts: 78478
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: split string and looping item
Adeel and Alan, Sal21 is working in VB6, not in Excel.
Best wishes,
Hans
Hans