in VBA how to retreive cell values 1 byte at a time?

  • Thread starter Thread starter d_penny
  • Start date Start date
D

d_penny

How would I write VBA to retrieve (get at) the value in a cell byte by
byte from its natural form? i.e. no conversions are to be performed.
E.g., if a string, then I may get more bytes than for a number.

Thanks.
 
Penny,

If the cell contains text, you can retrieve characters (bytes) with the MID
function.
=MID(A2, CharPosition, 1). You can get the actual byte values with the CODE
function
=CODE(MID(A2, CharPosition, 1)).


If a number, you can extract the decimal digits of the number in the same
way, but you're not getting actual bytes (as stored by Excel). Excel stores
numbers in an IEEE floating point standard format, the IEEE number of which
I can't recall at the moment. All such numbers use 8 bytes for storage in
that format. If you want the ASCII code values for the decimal digits of
the number, use the formula above, as with text.
 
Dim myVal

For Each cell In Selection
myVal= cell.Text
Next cell

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Penny,

Oops. You said you wanted to do this in VBA.

For a character:
Mid(Range("A2"), CharPosition, 1)

For the ASCII code value:
Asc(Mid(Range("A2"), CharPosition, 1))
 
Back
Top