View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default How to divide a number into various denominators

This uses a macro. Is that ok?

I put these values in B1:M1 (12 cells):
1000, 100, 50, 20, 10, 5, 1, 0.5, 0.25, 0.1, 0.05, 0.01

($1000 bill, $100 bill, $50, ..., thru a penny (.01))

I put this in A2: 1234.32

Then I added this function from Chip Pearson into a General module.

Option Explicit
Function ConvertToCurrency(ByVal Amt As Double) As Variant
Dim Ndx As Integer
Dim Counter As Integer
Dim Arr As Variant
Arr = Array(1000, 100, 50, 20, 10, 5, 1, 0.5, 0.25, 0.1, 0.05, 0.01)
For Ndx = LBound(Arr) To UBound(Arr)
Counter = 0
While (Amt + 0.001) = Arr(Ndx)
Counter = Counter + 1
Amt = Amt - Arr(Ndx)
Wend
Arr(Ndx) = Counter
Next Ndx
ConvertToCurrency = Arr
End Function

Then I selected B2:M2 and typed:
=converttocurrency(a2)
but instead of hitting enter, I hit ctrl-shift-enter.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

If you need more currency ($500), just add it to your headers, put it in the
code and select as many cells as required (12 will become 13 in my example).

Remember to hit ctrl-shift-enter to enter the formula.

maa wrote:

How to divide a number into various denominators eg thousands, hundreds,
tens, fives & ones for example 5527 can be divided into 5 (thousand), 5
(hundreds), 2(tens) & 7 (ones).


--

Dave Peterson