@rugila:
A Howdy from Arizona
Say, I was in my 'near-death' laptop, but back on a decent PC today. Like you, I'm limited to Excel2003, so same rows.
Anyways, I ran into an issue where if we're real close to having the sheet full, q + resize stp can error, as its trying assign rows to 'a' that aren't there.
Probably something more graceful, but tacking the below under ReDim c(... seems to get it to right to the sheet's last row but no further.
<font face=Courier New> <SPAN style="color:#00007F">ReDim</SPAN> c(1 <SPAN style="color:#00007F">To</SPAN> stp, 1 <SPAN style="color:#00007F">To</SPAN> 1)<br> <br> <SPAN style="color:#007F00">'// Added ***********************************//</SPAN><br> <SPAN style="color:#00007F">If</SPAN> q + stp > Rows.Count <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#007F00">'//</SPAN><br> stp = stp - ((stp + q) - Rows.Count) <SPAN style="color:#007F00">'//</SPAN><br> <SPAN style="color:#00007F">ReDim</SPAN> c(1 <SPAN style="color:#00007F">To</SPAN> stp, 1 <SPAN style="color:#00007F">To</SPAN> 1) <SPAN style="color:#007F00">'//</SPAN><br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#007F00">'//</SPAN><br> <SPAN style="color:#007F00">'// End*************************************//</SPAN></FONT>
Hopefully my observation isn't daffy...
...The interesting part is that I also ran this macro for a test on a different data set, and the amount of time it took to process 773,000 rows was much more similar to your clocked times (11 seconds).
Doug:
It may help if you show good data examples; several strings of the stuff that works and several of the stuff that goes kaboom.
Not sure if this will work until we see the strings, but here was what I came up with. I should preface this with I know nil about RegExp, but this seems to find the stops/dots and replace them while still in the original strings. From there, I stayed with trying TextToColumns.
One downside, if a given val has two stops, both get replaced; as in ".2.2321" becomes "US.2US.232"; so this suggestion is only considerable if you know you'll have a max of one stop per element.
<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br><br><SPAN style="color:#00007F">Sub</SPAN> Text2Col_ArrayGetChunks_ver3()<br><br>Dim _<br>lLRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _<br>lRemainder <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _<br>lChunkCount <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _<br>i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _<br>ii <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _<br>rngCurrent <SPAN style="color:#00007F">As</SPAN> Range, _<br>aryRange<br><br><SPAN style="color:#00007F">Dim</SPAN> REXP <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN> <SPAN style="color:#007F00">'<--- RegExp</SPAN><br><br><SPAN style="color:#007F00">'Dim Start As Single: Start = Timer</SPAN><br><br><SPAN style="color:#00007F">Const</SPAN> CHUNK_SIZE <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN> = 10000 <SPAN style="color:#007F00">'<---Increase to suit.</SPAN><br> <br> <SPAN style="color:#00007F">Set</SPAN> REXP = CreateObject("VBScript.RegExp")<br> REXP.Global = <SPAN style="color:#00007F">True</SPAN><br> REXP.Pattern = "\."<br> Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br> <SPAN style="color:#00007F">With</SPAN> ActiveSheet <SPAN style="color:#007F00">'Sheet2</SPAN><br> <br> lLRow = .Cells(Rows.Count, "D").End(xlUp).Row<br> lChunkCount = lLRow \ CHUNK_SIZE<br> lRemainder = lLRow Mod CHUNK_SIZE<br> <SPAN style="color:#00007F">ReDim</SPAN> aryRange(1 <SPAN style="color:#00007F">To</SPAN> CHUNK_SIZE, 1 <SPAN style="color:#00007F">To</SPAN> 1)<br> <br> <SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> lChunkCount<br> <SPAN style="color:#00007F">Set</SPAN> rngCurrent = .Range(.Cells((i * CHUNK_SIZE + 1) - CHUNK_SIZE, "D"), _<br> .Cells(i * CHUNK_SIZE, "D"))<br> <br> aryRange = .Range(.Cells((i * CHUNK_SIZE + 1) - CHUNK_SIZE, "D"), _<br> .Cells(i * CHUNK_SIZE, "D")).Value<br> <br> <SPAN style="color:#00007F">For</SPAN> ii = <SPAN style="color:#00007F">LBound</SPAN>(aryRange, 1) <SPAN style="color:#00007F">To</SPAN> <SPAN style="color:#00007F">UBound</SPAN>(aryRange, 1)<br> aryRange(ii, 1) = REXP.Replace(aryRange(ii, 1), "US.")<br> <SPAN style="color:#00007F">Next</SPAN><br> rngCurrent.Value = aryRange<br> rngCurrent.TextToColumns Destination:=rngCurrent(1, 1), _<br> DataType:=xlDelimited, _<br> TextQualifier:=xlTextQualifierNone, _<br> Other:=True, OtherChar:="~", _<br> FieldInfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2), _<br> Array(6, 2), Array(7, 2), Array(8, 2), Array(9, 2), Array(10, 2), _<br> Array(11, 2), Array(12, 2), Array(13, 2), Array(14, 2), Array(15, 2), _<br> Array(16, 2), Array(17, 2), Array(18, 2), Array(19, 2), Array(20, 2), _<br> Array(21, 2), Array(22, 2), Array(23, 2), Array(24, 2), Array(25, 2), _<br> Array(26, 2), Array(27, 2), Array(28, 2), Array(29, 2), Array(30, 2), _<br> Array(31, 2), Array(32, 2), Array(33, 2), Array(34, 2), Array(35, 2))<br> <br> <SPAN style="color:#00007F">Next</SPAN><br> <br> <SPAN style="color:#00007F">If</SPAN> lRemainder > 0 <SPAN style="color:#00007F">Then</SPAN><br> <SPAN style="color:#00007F">Set</SPAN> rngCurrent = .Range(.Cells((i * CHUNK_SIZE + 1) - CHUNK_SIZE, "D"), _<br> .Cells(.Cells( _<br> (i * CHUNK_SIZE + 1) - CHUNK_SIZE, "D").Row _<br> + lRemainder - 1, "D" _<br> ) _<br> )<br> aryRange = .Range(.Cells((i * CHUNK_SIZE + 1) - CHUNK_SIZE, "D"), _<br> .Cells(.Cells( _<br> (i * CHUNK_SIZE + 1) - CHUNK_SIZE, "D").Row _<br> + lRemainder - 1, "D" _<br> ) _<br> )<br> <SPAN style="color:#00007F">For</SPAN> ii = <SPAN style="color:#00007F">LBound</SPAN>(aryRange, 1) <SPAN style="color:#00007F">To</SPAN> <SPAN style="color:#00007F">UBound</SPAN>(aryRange, 1)<br> aryRange(ii, 1) = REXP.Replace(aryRange(ii, 1), "US.")<br> <SPAN style="color:#00007F">Next</SPAN><br> rngCurrent.Value = aryRange<br> rngCurrent.TextToColumns Destination:=rngCurrent(1, 1), _<br> DataType:=xlDelimited, _<br> TextQualifier:=xlTextQualifierNone, _<br> Other:=True, OtherChar:="~", _<br> FieldInfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2), _<br> Array(6, 2), Array(7, 2), Array(8, 2), Array(9, 2), Array(10, 2), _<br> Array(11, 2), Array(12, 2), Array(13, 2), Array(14, 2), Array(15, 2), _<br> Array(16, 2), Array(17, 2), Array(18, 2), Array(19, 2), Array(20, 2), _<br> Array(21, 2), Array(22, 2), Array(23, 2), Array(24, 2), Array(25, 2), _<br> Array(26, 2), Array(27, 2), Array(28, 2), Array(29, 2), Array(30, 2), _<br> Array(31, 2), Array(32, 2), Array(33, 2), Array(34, 2), Array(35, 2))<br> <br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br> Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br> <br> <SPAN style="color:#00007F">Set</SPAN> REXP = <SPAN style="color:#00007F">Nothing</SPAN><br> <br><SPAN style="color:#007F00">'Debug.Print "Text2Col_ArrayGetChunks_ver3: " & Timer - Start</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
If the "US." part is not critical, this seems to go ok.
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Text2Col_GetChunks_ver2()<br> <br>Dim _<br>lLRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _<br>lRemainder <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _<br>lChunkCount <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _<br>i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _<br>rngCurrent <SPAN style="color:#00007F">As</SPAN> Range<br> <br><SPAN style="color:#00007F">Dim</SPAN> Start <SPAN style="color:#00007F">As</SPAN> Single: Start = Timer<br> <br><SPAN style="color:#00007F">Const</SPAN> CHUNK_SIZE <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN> = 10000 <SPAN style="color:#007F00">'<---Increase to suit.</SPAN><br> <br> Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br> <SPAN style="color:#00007F">With</SPAN> ActiveSheet <SPAN style="color:#007F00">'Sheet2</SPAN><br> <br> lLRow = .Cells(Rows.Count, "D").End(xlUp).Row<br> <br> lChunkCount = lLRow \ CHUNK_SIZE<br> lRemainder = lLRow Mod CHUNK_SIZE<br> <br> <SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> lChunkCount<br> <SPAN style="color:#00007F">Set</SPAN> rngCurrent = .Range(.Cells((i * CHUNK_SIZE + 1) - CHUNK_SIZE, "D"), _<br> .Cells(i * CHUNK_SIZE, "D"))<br> <br> rngCurrent.TextToColumns Destination:=rngCurrent(1, 1), _<br> DataType:=xlDelimited, _<br> TextQualifier:=xlTextQualifierNone, _<br> Other:=True, OtherChar:="~", _<br> FieldInfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2), _<br> Array(6, 2), Array(7, 2), Array(8, 2), Array(9, 2), Array(10, 2), _<br> Array(11, 2), Array(12, 2), Array(13, 2), Array(14, 2), Array(15, 2), _<br> Array(16, 2), Array(17, 2), Array(18, 2), Array(19, 2), Array(20, 2), _<br> Array(21, 2), Array(22, 2), Array(23, 2), Array(24, 2), Array(25, 2), _<br> Array(26, 2), Array(27, 2), Array(28, 2), Array(29, 2), Array(30, 2), _<br> Array(31, 2), Array(32, 2), Array(33, 2), Array(34, 2), Array(35, 2))<br> <SPAN style="color:#00007F">Next</SPAN><br> <br> <SPAN style="color:#00007F">If</SPAN> lRemainder > 0 <SPAN style="color:#00007F">Then</SPAN><br> <SPAN style="color:#00007F">Set</SPAN> rngCurrent = .Range(.Cells((i * CHUNK_SIZE + 1) - CHUNK_SIZE, "D"), _<br> .Cells(.Cells( _<br> (i * CHUNK_SIZE + 1) - CHUNK_SIZE, "D").Row _<br> + lRemainder - 1, "D" _<br> ) _<br> )<br> <br> rngCurrent.TextToColumns Destination:=rngCurrent(1, 1), _<br> DataType:=xlDelimited, _<br> TextQualifier:=xlTextQualifierNone, _<br> Other:=True, OtherChar:="~", _<br> FieldInfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2), _<br> Array(6, 2), Array(7, 2), Array(8, 2), Array(9, 2), Array(10, 2), _<br> Array(11, 2), Array(12, 2), Array(13, 2), Array(14, 2), Array(15, 2), _<br> Array(16, 2), Array(17, 2), Array(18, 2), Array(19, 2), Array(20, 2), _<br> Array(21, 2), Array(22, 2), Array(23, 2), Array(24, 2), Array(25, 2), _<br> Array(26, 2), Array(27, 2), Array(28, 2), Array(29, 2), Array(30, 2), _<br> Array(31, 2), Array(32, 2), Array(33, 2), Array(34, 2), Array(35, 2))<br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br> Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br> <br>Debug.Print "Text2Col_GetChunks_ver2: " & Timer - Start<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
Mark