Frage

I'm in need of a formula that rounds numbers differently depending on if the number is tens, hundreds, thousands, hundred-thousands, millions, etc. I know the basic rounding functions in Excel but not sure how to do this exactly.

Examples:

1 - 999 need to be rounded up to the nearest 10.
1.000 - 99.999 need to be rounded up to the nearest 100.
100.000 - 999.999 need to be rounded up to the nearest 1.000.
1.000.000 - 999.999.999 need to be rounded up to the nearest 100.000.
1.000.000.000 - 999.999.999.999 need to be rounded up to the nearest 1.000.000

And all this in single formula that can easily be copied down.

Any help would be greatly appreciated!

War es hilfreich?

Lösung 2

Probably the best way to do it would be a custom VBA function switching between values - That would give you the most amount of control, but you could do it with nested IF() statements too:

=IF(A1<1000,CEILING(A1,10),IF(A1<100000,CEILING(A1,100),IF(A1<1000000,CEILING(A1,1000),IF(A1<1000000000,CEILING(A1,100000),CEILING(A1,1000000)))))

Hope that helps!!

Andere Tipps

You can use ROUNDUP function with a LOOKUP function nested to give you the logic you need, i.e. with values in A2 down use this formula in B2 copied down

=ROUNDUP(A2,LOOKUP(A2,10^{0,3,5,6,9},-{1,2,3,5,6}))

This part

10^{0,3,5,6,9}

defines the lower bound of each range. And this part:

-{1,2,3,5,6}

gives the number of digits to round to, e.g. -2 gives next 100, -3 next 1000 etc.

This rounds up to the nearest multiple of 100 etc. so 134 will round to 140. If you want to round to the nearest multiple then you can use the exact same formula but with ROUND in place of ROUNDUP

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top