VBA CByte function

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.50 out of 5)
Loading...

CByte Function Description

The VBA CByte function converts an expression (variable) to Byte data type.

Syntax

The syntax for the CByte function in VBA is:

CByte( expression )

Parameters

expression
An expression / variable that is to be converted to Byte data type.

Other Notes

The Byte data type restricts value from 0 to 255. Converted fractions will be rounded (banker’s rounding algorithm).

Number higher that 255 and lower than 0 will throw Overflow error.

Example usage

The CByte function can be used in VBA code. Let’s look at some VBA CByte function examples:

CByte 10 
'Result: 10

CByte "20"
'Result: 20

CByte 20.2
'Result: 20

CByte 20.6
'Result: 21

Simply the best place to learn VBA!

Error: Please enter a valid email address

Error: Invalid email

Error: Please enter your first name

Error: Please enter your last name

Error: Please enter a username

Error: Please enter a password

Error: Please confirm your password

Error: Password and password confirmation do not match