Learn Excel - Simplify Life with Excel Concepts

Excel CByte Function (VBA)

Cbyte Function VBA Code

How to use the CByte Function (VBA)

This Excel tutorial explains how to use the Excel CByte function with syntax and examples using VBA.

SUMMARY:

The Excel VBA CByte function converts an expression into a Byte data type. It converts a value to a byte (ie: number between 0 and 255).

For example,

  • The VBA Code CByte(10) would return 10.
  • The VBA Code CByte(3.95) would return 4.

PURPOSE:

To converts a value to a Byte.

RETURN VALUE:

The CByte function returns a Byte value.

SYNTAX:

CByte( expression )

ARGUMENTS:

The CByte function syntax has the following arguments:

  • expression: Required. The expression that you want to convert to a Byte.
    • It can hold simple integer values between 0 and 255.
    • The supplied Expression must be able to be intepreted as (or converted into) an integer between 0 and 255.
    • The "expression" can be any numerical value between 0 to 255 (Integer).

REMARKS:

  • The CByte function can only be used in VBA code in Microsoft Excel.
  • If the expression can be any numerical value between 0 to 255 (Integer).
  • A byte takes up a single byte of computer memory and can have a value from 0 to 255.
  • If the expression is not a floating point number then it is rounded to the nearest integer.
  • This data type is commonly used for file formats and data conversions.
  • An overflow error will occur if the value is out of range.

Useful Links: Link 1Link 2Link 3Link 4