This is quite possibly the most clever VBA code I have ever seen.
There's not much room for improvement here, except a couple naming nitpicks:
- If that's what they stand for, functions
shrandshlcould afford to be calledShiftRightandShiftLeft. - I don't see a reason for
shrandshlto not follow the PascalCasing naming convention. - Given the almost-flawlessly consistent camelCasing convention for locals & parameters, I don't see a reason for
ValueandShiftparameters to not stick to it. (except perhaps VBA/VB6's stubornness with casing?)
As for string handling, as per this source AscW is faster than Asc so again, good call:
AscW(Mid$(..)) considerations
Don't copy too many characters with Mid$. AscW only examines the first character anyway. AscW(Mid$(s, x, 1)) is the best call. Note that if you call AscW(Mid$(s, x)) without the third parameter, Mid$ executes slowly when s is a long string.
Example of potentially slow code:
For x = 1 To Len(s) If AscW(Mid$(s, x)) = ... Then ... NextThe above is better written as:
For x = 1 To Len(s) If AscW(Mid$(s, x, 1)) = ... Then ... Next