View Single Post
  #15   Report Post  
Posted to microsoft.public.excel.programming
Jim Becker Jim Becker is offline
external usenet poster
 
Posts: 11
Default Removing Leading Zeros from a String

Upon testing I concede the point. Your test program, as written, did not
provide a valid comparison, since it did not transfer the data back into the
range. I modified as per below and then ran ten tests of each on my
(admittedly) slow processor. Your StripLeadingZeros2 averaged 370 msecs vs.
my average of 607.

Sub teststripping2()

Dim arr()
Dim i As Long

arr = Range(Cells(1), Cells(15000, 1))

StartTimer

For i = 1 To 15000
arr(i, 1) = StripLeadingZeros2(arr(i, 1))
Next

Range(Cells(1), Cells(15000, 1)) = arr

MsgBox EndTimer

End Sub

"RB Smissaert" wrote in message
...
Haven't tested, but can't believe that is faster.
I would think the fastest way is to assign the sheet range to an array,

run
one of the
mentioned fast functions on this array and then put the array in the

sheet.
Even if it wasn't faster I prefer VBA above sheet formula's. It just looks
so messy.
I suppose it is just personal taste.

RBS


"Jim Becker" wrote in message
...
"RB Smissaert" wrote in message
...

If somebody can show me something that is faster I would be

interested.


Since you asked ;)

Sub How_Would_Dana_Do_It()
'Assumes data is in column A, headings in row 1
Columns("A").Insert
With Range(Range("A2"), Range("B65536").End(xlUp).Offset(, -1))
.Formula = "=TEXT(LEFT(B2,FIND(""-"",B2)-1),""General"")" & _
"&MID(B2,FIND(""-"",B2),50)"
.Value = .Value
End With
Range("A1").Value = Range("B1").Value
Columns("B").Delete
End Sub

--
Hope this helps,
James dot Becker at NCR dot com
~
~
~
:wq!