This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I've got some code below, to choose the amount of bills or coins to make an amount. In this case I'm just trying to see how many coins are required to make 3 cents. For some reason the output is giving me 2 pennies rather than 3.
The problem's happening after 2 pennies. The Do While Loop should be thinking cells(i,1) = 0.01 which is <= amount (amount ie remaining amount at this point is 0.01) and should then go into the loop. But it seems like it's ignoring that loop. Not sure why?
To start please write "0.03" in cell b2 and "0.01" in cell a16. there's a bunch of other bills and coins but not necessary to debug this part.
Private Sub CommandButton1_Click()
Dim amount As Double
amount = Range("b2")
Range("b5:b16").Clear
For i = 5 To 16
Do While Cells(i, 1) <= amount
Cells(i, 2) = Cells(i, 2) 1
amount = amount - Cells(i, 1)
Loop
Next i
End Sub
Subreddit
Post Details
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/excel/comme...