View Single Post
  #25   Report Post  
Posted to microsoft.public.excel.worksheet.functions
joeu2004 joeu2004 is offline
external usenet poster
 
Posts: 2,059
Default VBA range selection question

On May 9, 9:01*pm, "Rick Rothstein"
wrote:
here is the generalization of the function I asked you
(Joe) to time test; it will work with XL2007 and XL2010


I would implement the two methods as follows:

Byte method:

Const lcA As Long = 96 'Asc("a")-1
Dim b() As Byte
[....]
b = mycolumn
For k = 0 To UBound(b) Step 2
getcolnum = 26 * getcolnum + (b(k) Or 32) - lcA
Next

String method:

Const lcA As Long = 96 'Asc("a")-1
[....]
For k = 1 To Len(mycolumn)
getcolnum = 26 * getcolnum + _
(Asc(Mid(mycolumn, k, 1)) Or 32) - lcA
Next

Note that I use "Or 32" in place of LCase. I did not measure the
benefit.

I found that the String method significantly outperforms the Byte for
Len(mycolumn) <= 3 (52%, 38% and 3.6% faster). The Byte method
increasingly outperforms the String method for Len(mycolumn) = 4
(21%, 33% etc faster).

Apparently, the assignment byte=string adds significant overhead to
the Byte method. When I replace it with Dim b(0 to 1) and discrete
assignments of constants to b(0) and b(1) for the one-character case,
the Byte method is about 1.2% faster than the String method.