I am trying to list hexadecimal values from 7F down to 00 per Excel row. I achieved it by doing the following code:
Sub ListDownHex()
Dim StartValue, i As Integer
Dim nRow As Long
Dim sh As Worksheet
Set sh = ActiveSheet
StartValue = 127 'memory location of 8051 RAM
nRow = 4
For i = StartValue To 0 Step -1
sh.Range("A" & nRow) = Format(Right$("00" & Hex(i), 2), "00")
nRow = nRow + 1
Next i
End Sub
except hex values that have "A" like "7A", "6A", "5A", etc. result to "00". Further check on Intermediate Window confirms Format() function does it.
? Format("7B","00") 'desired output
7B
? Format("7A","00") 'not expected output
00
Is this a bug or am I missing something? Why are they acting differently? (Note: The focus of my question is on "strange" behavior of Format() not on my entire code.)