Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. round function in VBA

round function in VBA

Scheduled Pinned Locked Moved Visual Basic
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephan Wright
    wrote on last edited by
    #1

    Hy everyone! I do have the following situation DIM myint as Integer DIM myreal1 as VARIANT DIM myreal2 as VARIANT myint = myreal1 / myreal2 VBA in Excel does the following: If myreal1/myreal2 < xx.5 then round to next LOWER integer if myreal1/myreal2 >= xx.5 then round to next HIGHER integer But I do want the result to be round to next LOWER integer EVERYTIME! meaning 0,95 should be 0 and 0,45 aswell In C there is a function name floor() which does this, but I could not find a similar function in VBA. If anyone knows the relevant function in VBA please let me know. Thanks! Stephan.

    S J 2 Replies Last reply
    0
    • S Stephan Wright

      Hy everyone! I do have the following situation DIM myint as Integer DIM myreal1 as VARIANT DIM myreal2 as VARIANT myint = myreal1 / myreal2 VBA in Excel does the following: If myreal1/myreal2 < xx.5 then round to next LOWER integer if myreal1/myreal2 >= xx.5 then round to next HIGHER integer But I do want the result to be round to next LOWER integer EVERYTIME! meaning 0,95 should be 0 and 0,45 aswell In C there is a function name floor() which does this, but I could not find a similar function in VBA. If anyone knows the relevant function in VBA please let me know. Thanks! Stephan.

      S Offline
      S Offline
      Stephan Wright
      wrote on last edited by
      #2

      I just found out myself. it's the int() function in VBA Stephan.

      1 Reply Last reply
      0
      • S Stephan Wright

        Hy everyone! I do have the following situation DIM myint as Integer DIM myreal1 as VARIANT DIM myreal2 as VARIANT myint = myreal1 / myreal2 VBA in Excel does the following: If myreal1/myreal2 < xx.5 then round to next LOWER integer if myreal1/myreal2 >= xx.5 then round to next HIGHER integer But I do want the result to be round to next LOWER integer EVERYTIME! meaning 0,95 should be 0 and 0,45 aswell In C there is a function name floor() which does this, but I could not find a similar function in VBA. If anyone knows the relevant function in VBA please let me know. Thanks! Stephan.

        J Offline
        J Offline
        Just Greeky Creek
        wrote on last edited by
        #3

        Public Function Ceiling(ByVal X As Double, Optional ByVal Factor As Double = 1) As Double ' X is the value you want to round ' is the multiple to which you want to round Ceiling = (Int(X / Factor) - (X / Factor - Int(X / Factor) > 0)) * Factor End Function Public Function Floor(ByVal X As Double, Optional ByVal Factor As Double = 1) As Double ' X is the value you want to round ' is the multiple to which you want to round Floor = Int(X / Factor) * Factor End Function

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups