Coming soon - Get a detailed view of why an account is flagged as spam!
view details

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.

1
my vba code is getting an incorrect answer, off by one loop
Post Flair (click to view more posts with a particular flair)
Post Body

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

Author
Account Strength
70%
Account Age
1 year
Verified Email
Yes
Verified Flair
No
Total Karma
8,404
Link Karma
2,754
Comment Karma
5,650
Profile updated: 5 days ago
Posts updated: 10 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago