Excel macro: how to use floor function in macro code

georgemathew46

New Member
Joined
Jun 5, 2013
Messages
22
Hi,

i am trying to get a floor value in excel macro.

eg:
assume x=20
(x/9)=2.222
but i want to print as 3 which can be accomplished using floor function.
but am not able to use excel inbuilt functions in macro.

like floor(x/9) which throws me a error: function not found.

Please help me out .. :confused:
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
19,257
Office Version
  1. 2013
Platform
  1. Windows
x/9 will give 2.222, but the Floor function will give you 2 not 3.
To get 3 you will need the Ceiling function
Code:
Sub MM1()
Dim x As Integer
x = 20
ans = Application.Floor(x / 9, 1)
MsgBox ans
End Sub



Sub MM2()
Dim x As Integer
x = 20
ans = Application.Ceiling(x / 9, 1)
MsgBox ans
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,109,013
Messages
5,526,268
Members
409,689
Latest member
martin_br

This Week's Hot Topics

Top