Using an array would make it much simpler tochange the code should the 50
cent piece be eliminated, and a 3 dollar bill added. No need to declare
different variables: you simply change the definition of the 2 arrays.
Yep: except for the 240 pence to the pound...
Public Function CalcChange(PayOutDue As Currency) As String
Dim TotalCents As Currency
Dim Dollars As Currency
Dim Cents As Currency
Dim Sizes As Variant
Dim Denoms As Variant
Dim iSize As Integer
Dim HowMany As Integer
Dim OfWhat As String
Denoms = Array(" Five Pound", " Two Pound", " Guinea", " Sovereign", _
" Half Sovereign", " Crown", " Half Crown", " Florin", " Shilling", _
" Sixpence", " Threepence", " Twopence", " Penny")
Sizes = Array(1200, 480, 252, 240, 120, 60, 30, 24, 12, 6, 3, 2, 1)
TotalCents = PayOutDue * 240
For iSize = 0 To UBound(Denoms)
HowMany = TotalCents \ Sizes(iSize)
If HowMany > 0 Then
OfWhat = Denoms(iSize)
If HowMany > 1 Then
If Right(OfWhat, 1) = "y" Then
OfWhat = Left(OfWhat, Len(OfWhat) - 1) & "ies"
Else
OfWhat = OfWhat & "s"
End If
End If
CalcChange = CalcChange & HowMany & OfWhat & ", "
End If
TotalCents = TotalCents Mod Sizes(iSize)
Next iSize
CalcChange = Left(CalcChange, Len(CalcChange) - 2)
End Function
John W. Vinson [MVP]