D
DS
I want the message box to pop up if when you divide the number and its less
than .00 but it's not doing this.
I suspect that the number is a decimal .0096 or some like that. But it
should also stop in that case. Any help appreciated.
Thanks
DS
Public Function SC(myNum As Currency, X As Integer)
Dim myNums As String
Dim myNumDivByX As Currency
Dim portion(100) As Currency
Dim i As Currency
Dim leftover As Currency
Dim absleftover As Currency
Dim addon As Currency
myNumDivByX = Round(myNum / X, 2)
'If a number is less than 0.00
If myNumDivByX = 0# Then
MsgBox "STOP"
ElseIf (myNumDivByX * X) = myNum Then
For i = 1 To X
portion(i) = myNumDivByX
myNums = myNums & portion(i) & vbCrLf
Next i
ElseIf (myNumDivByX * X) <> myNum Then
leftover = myNum - (myNumDivByX * X)
absleftover = Abs(leftover)
If leftover < 0 Then
addon = -0.01
Else
addon = 0.01
End If
For i = 1 To X
If i <= absleftover * 100 Then
portion(i) = myNumDivByX + addon
Else
portion(i) = myNumDivByX
End If
myNums = myNums & portion(i) & vbCrLf
Next i
End If
SC = myNums
End Function
than .00 but it's not doing this.
I suspect that the number is a decimal .0096 or some like that. But it
should also stop in that case. Any help appreciated.
Thanks
DS
Public Function SC(myNum As Currency, X As Integer)
Dim myNums As String
Dim myNumDivByX As Currency
Dim portion(100) As Currency
Dim i As Currency
Dim leftover As Currency
Dim absleftover As Currency
Dim addon As Currency
myNumDivByX = Round(myNum / X, 2)
'If a number is less than 0.00
If myNumDivByX = 0# Then
MsgBox "STOP"
ElseIf (myNumDivByX * X) = myNum Then
For i = 1 To X
portion(i) = myNumDivByX
myNums = myNums & portion(i) & vbCrLf
Next i
ElseIf (myNumDivByX * X) <> myNum Then
leftover = myNum - (myNumDivByX * X)
absleftover = Abs(leftover)
If leftover < 0 Then
addon = -0.01
Else
addon = 0.01
End If
For i = 1 To X
If i <= absleftover * 100 Then
portion(i) = myNumDivByX + addon
Else
portion(i) = myNumDivByX
End If
myNums = myNums & portion(i) & vbCrLf
Next i
End If
SC = myNums
End Function