As Scott Kraner noted, downtime Right("000000" & endadd,6)will work just fine, but it Right$("000000" & endadd,6)will be a little faster.
Also, in terms of performance, it really depends on whether the original source of the value is a endaddstring or a digit.
'CONCAT String Approach
'If the hex source is a string, then this is the most efficient approach
formattedHex = Right$("000000" & "12F", 2)
'CONCAT Numeric Approach
'But if the hex source is a numeric, then this hex conversion AND concatenation is required, but it is SLOW
formattedHex = Right$("000000" & Hex$(&H12F), 2)
'ADDITION/OR Numeric Approach
'When the hex source is numeric it is more efficient to use a bit trick to add AND convert
formattedHex = Right$(Hex$(&H1000000 + &H12F), 2)
formattedHex = Right$(Hex$(&H1000000 Or &H12F), 2)
10 m duty cycle results:
Approach | Using Right | Using Right$ |
==========================+=============================
CONCAT String Approach | 1.59s | 1.40s
CONCAT Numeric Approach | 2.63s | 2.33s
ADDITION Numeric Approach | 1.74s | 1.60s
======================================================
source
share