Ron,
Try my modified version of your code and see what you get.
~ 1.19 vs. 0.73
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)
'---
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Sub test()
Const Str As String = "Rehau - w/Shield Cvr & Package "
Dim sTemp() As String
sTemp = Split(Str)
Dim IDa As String
Dim dTimer As Long
Dim i As Long
Dim j As Long
Const lReps As Long = 100000 '<<<
dTimer = timeGetTime
For j = 1 To lReps
For i = 0 To UBound(sTemp)
If UCase(sTemp(i)) Like "[A-Z]*" Then
IDa = IDa & UCase(Left(sTemp(i), 1))
End If
Next i
IDa = vbNullString '<<<Note
Next j
MsgBox (timeGetTime - dTimer) / 1000
IDa = vbNullString
dTimer = timeGetTime
For j = 1 To lReps
For i = 0 To UBound(sTemp)
If sTemp(i) Like "[a-zA-Z]*" Then
IDa = IDa & UCase(Left(sTemp(i), 1))
End If
Next i
IDa = vbNullString '<<<Note
Next j
MsgBox (timeGetTime - dTimer) / 1000
End Sub
'---
"Ron Rosenfeld"
wrote in message
Well, I wondered about checking that. So I ran a routine identical except for
the comparison statement (see code below).
For 10,000 repetitions, the UCase variation took 0.4375 seconds, whereas the
[a-zA-Z] variant took 1.125 seconds. So it would appear the UCase is the more
"efficient".
=================================
Option Explicit
Sub test()
Const Str As String = "Rehau - w/Shield Cvr & Package "
Dim sTemp() As String
sTemp = Split(Str)
Dim IDa As String
Dim dTimer As Double
Dim i As Long
Dim j As Long
Const lReps As Long = 10000
dTimer = Timer
For j = 1 To lReps
For i = 0 To UBound(sTemp)
If UCase(sTemp(i)) Like "[A-Z]*" Then
IDa = IDa & UCase(Left(sTemp(i), 1))
End If
Next i
Next j
Debug.Print Timer - dTimer
dTimer = Timer
For j = 1 To lReps
For i = 0 To UBound(sTemp)
If sTemp(i) Like "[a-zA-Z]*" Then
IDa = IDa & UCase(Left(sTemp(i), 1))
End If
Next i
Next j
Debug.Print Timer - dTimer
End Sub
===========================
0.4375
1.125
=========================
--ron