Return only integer part of a number
This tutorial shows how to return only the integer component of a number through the use of an Excel formula, with the TRUNC function, or VBA.
Example: Return only integer part of a number
=TRUNC(B5)
|
This formula uses the TRUNC function to return only the integer part of a number.
|
Sub Return_only_integer_part_of_a_number()
'declare a variable
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'return only the integer part of a number that is captured in a specific cell
ws.Range("C5") = Fix(ws.Range("B5"))
ws.Range("C5") = Fix(ws.Range("B5"))
End Sub
ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("C5") in the VBA code.
Number from which to extract integer part: Select the cell that captures the number from which you want to extract only the integer part by changing the cell reference ("B5") in the VBA code.
Worksheet Selection: Select the worksheet which captures the cell from which you want to extract only the integer part by changing the Analysis worksheet name in the VBA code. You can also change the name of this object variable, by changing the name 'ws' in the VBA code.
Output Range: Select the output range by changing the cell reference ("C5") in the VBA code.
Number from which to extract integer part: Select the cell that captures the number from which you want to extract only the integer part by changing the cell reference ("B5") in the VBA code.
Worksheet Selection: Select the worksheet which captures the cell from which you want to extract only the integer part by changing the Analysis worksheet name in the VBA code. You can also change the name of this object variable, by changing the name 'ws' in the VBA code.
EXPLANATION
This tutorial shows how to extract only the integer part of a number by using an Excel formula, with the TRUNC function, or VBA.
FORMULA
=TRUNC(number)
=TRUNC(number)
ARGUMENTS
number: The number from which to extract only the integer part.
number: The number from which to extract only the integer part.
RELATED TOPICS
Related Topic | Description | Related Topic and Description |
---|---|---|
Return only decimal part of a number | How to return only the decimal component of a number using Excel and VBA | |
Return last numeric value in a column | How to return the last numeric value in a column using Excel and VBA | |
Return last numeric value in a row | How to return the last numeric value in a row using Excel and VBA | |
Return first word from a string | How to return the first word from a string using Excel and VBA | |
Return highest number | How to return the highest value from a range of values using Excel and VBA |