1. CByte VBA Function – Description
The CByte VBA function returns a value of the Byte data type. It is an integer in the range 0-255 . The Byte data type, as its name suggests,
occupies a memory space of 1B. This way, we can convert low-valued numbers to store them in more
efficient data types. The function can also be used to convert a number written as text to a number in the Byte data type. Attempting to call a
function with an argument outside the range 0-255 will generate an error.
2. VBA CByte Function – Syntax
Expression : Any integer in the range 0-255 stored in any data type (including String).
Function return : Byte / An integer in the range 0-255.
3. VBA CByte function – Example
How to use CByte function in VBA Excel? Below are examples of using the CByte function in the VisualBasic Editor.
Dim StrNumber As String StrNumber = "255" MsgBox CByte (StrNumber)
Dim LngNumber As Long LngNumber = 123 MsgBox CByte (LngNumber)
4. VB CByte function – Additional information
- The function used for numbers other than integers or outside the range 0-255 will return an error.
5. CByte VisualBasic function – Where to use?
The function can be used in: Excel 2003, Excel 2007, Excel 2010, Excel 2013, Excel 2016.
The article is part of the VBA Excel function list. You can find a list of all VBA functions at this address: VBA functions .