Excel VBA Oct Function

VBA Oct Function: The Oct function in VBA converts the given number into octal notation and returns the result as a string.

Syntax

Oct (Number)

Parameter

Number (required) – This parameter represents the numeric value that you want to convert to octal.

Return

This function returns a string value after converting the specified number into octal notation. If the number is a decimal, it will round it to the nearest integer before converting it to octal.

Example 1

Sub OctFunction_Example1()
 'Converting decimal values into octal notation.
 Dim oct_val As String
 oct_val = Oct(18)
 ' The variable oct_val will return the String "22".
 Cells(1, 1).Value = oct_val
 End Sub 

Output

2.20E+01

VBA Oct Function

Example 2

Sub OctFunction_Example2()
 'Converting hexadecimal value into octal notation.
 Dim oct_val As String
 oct_val = Oct(&H8E8)
 ' The variable oct_val will return the String "4350".
 Cells(1, 1).Value = oct_val
 End Sub 

Output

4.35E+03

VBA Oct Function

Example 3

Sub OctFunction_Example3()
 'Converting hexadecimal value into octal notation.
 Dim oct_val As String
 oct_val = Oct("Hello VBA")
 ' The variable oct_val will return type mis match error.
 Cells(1, 1).Value = oct_val
 End Sub 

Output

VBA Oct Function