1

I have a number which can always change. I want to find the previous hundredth of that number. I'm only able to find the closest hundredth. Here's how I'm doing it atm:

Dim  mynum as integer 
mynum = 549
Dim tempnumber as integer
tempnumber = Round(mynum / 100, 0) * 100 '>>> equals 500 which is correct

What if mynum was 551? >> it will get 600 which i don't want, i only want 500 whether the number is 556, 588, or 599, i want the number to still be 500.

I want it to be 599 >> 500, 799>> 700. Basically the hundredth of the current number.

  • Possible duplicate of [How to round a number in VBA to the nearest 5? (or 10 or X)](http://stackoverflow.com/questions/326476/how-to-round-a-number-in-vba-to-the-nearest-5-or-10-or-x) – Marc B Oct 04 '16 at 18:31
  • which is where the `or X` comes in... once you know how to round to a 10, then extending that to 100 should be trivial. and note that 599 rounding to 500 is NOT the nearest. That's simply rounding DOWN. 599 would round 600 if you're rounding to "nearest". – Marc B Oct 04 '16 at 18:36
  • @ScottCraner that did it. thanks! – JustAnotherPersonYouDontKnow Oct 04 '16 at 18:38

1 Answers1

1

There are two ways to do this:

Round((mynum-50)/100,0)*100

And using the Worksheet Function:

Application.WorksheetFunction.RoundDown(mynum,-2)
Scott Craner
  • 148,073
  • 10
  • 49
  • 81