Removing Leading Zeros from a String
If you have a large number of cells to strip you may want the fastest
possible
function. I think this is quite efficient:
Function StripLeadingZeros(strNumber As String) As String
Dim i As Long
Dim byteArray() As Byte
byteArray = strNumber
For i = 0 To UBound(byteArray) Step 2
If Not byteArray(i) = 48 Then
StripLeadingZeros = Right(strNumber, Len(strNumber) - i / 2)
Exit For
End If
Next
End Function
If somebody can show me something that is faster I would be interested.
RBS
"MARTY" wrote in message
...
Greetings!
I have a worksheet which contains about 15000 rows, one
column of which is a dashed number sequence. Example:
0000123-45-67
I would like to remove the leading zeros. Note that
there are not always four zeros in front of the first
number (sometimes there are more, sometimes less). Is
there anything that can be done using VBA to remove the
zeros?
Thanks,
MARTY
|