Learn Excel - Simplify Life with Excel Concepts

Excel CLng Function (VBA)

CLng Function VBA Code

How to use the CLng Function (VBA)

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

SUMMARY:

The Excel VBA CLng function converts an expression into a Long data type.

For example,

  • The VBA Code CLng(22426.55) would return 22427
  • The VBA Code CLng(33.955555) would return 34

PURPOSE:

To converts a value to an Long Integer type.

RETURN VALUE:

The CLng function returns a Long Integer value.

SYNTAX:

CLng( expression )

ARGUMENTS:

The CLng function syntax has the following arguments:

  • expression: Required. The expression is that you want to convert to a long Integer.
    • The "expression" can be any value between -2,147,483,648 and 2,147,483,647
    • If "expression" is outside the range of the data type being converted to, an error occurs.
    • If "expression" includes any fractions or decimals these are rounded.
      • Any fractional parts less than or equal to 0.5 are rounded down to the nearest even number.
      • Any fractional parts greater than 0.5 are rounded up.

REMARKS:

  • The CLng function can only be used in VBA code in Microsoft Excel.
  • The Long data type is a Value data type.
  • VBAs hexadecimal notation symbol is "&H"
  • The Integer data type can hold integer values between (- 2.1 E+9) and (2.1 E+9)

Useful Links: Link 1Link 2Link 3Link 4