VBA Byte Data Type in Excel explained with syntax and examples. It contains binary data and holds a value from 0 through 255. Byte type is categorized as a numeric data type. The default value of byte is 0. It is used to save space in memory. It is smaller than integer data type. We shouldn’t assign negative number or greater than 255 value to byte variable. If we assign it returns or throws an overflow error. We can add a prefix literal &b or &B. It denotes a binary literal.
Syntax of the Byte Data type in Excel VBA
Let us see Data Type Byte Syntax in Excel VBA.
Dim VariableName As Byte
Where VariableName represents the name of the variable.
The Byte represents the data type of the variable.
Example1: The Byte variable value is 200
Here is an example on Byte VBA Data Type in Excel VBA when value is 200.
Sub VBAF1_Byte_DataType() 'Variable declaration Dim bByte As Byte 'Assign value to variable bByte = 200 End Sub
Example2: The Byte variable value is 400
Let us see one more example when value is 400.
Sub VBAF1_Byte_DataType() 'Variable declaration Dim bByte As Byte 'Assign value to variable bByte = 400 End Sub
Example3: The Byte variable value is negative
Sub VBAF1_Byte_DataType() 'Variable declaration Dim bByte As Byte 'Assign value to variable bByte = -600 End Sub
The above two macro throws an error. Because the byte variable value is more than 255 in the second example and value is negative in third example. Here is screenshot for your reference.
Convert an Expression to Byte VBA Data Type
You can convert an expression to byte VBA data type using VBA CByte function. Click on the following link to learn about CByte function and complete tutorial and examples.
Also read about all other data types.
Instructions to Run VBA Macro Code or Procedure:
You can refer the following link for the step by step instructions.
Instructions to run VBA Macro Code
Other Useful Resources:
Click on the following links of the useful resources. These helps to learn and gain more knowledge.
VBA Tutorial VBA Functions List VBA Arrays VBA Text Files VBA Tables
VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers Blog