I had to look at the worksheet and your copy of the instructions to figure this out, but I see now what they want. So you think you know what you have to do, except the part about the If statement, right?
I don't know whether you meant it literally or you just speaking loosely, but you wrote "IF function" in the subject of this thread while the assignment says "If statement". The assignment said it right. Technically you could use an Excel IF function in VBA, but that's going around your elbow to get to your thumb.
You already know what an IF function looks like in Excel. In VBA, an If statement looks different but does much the same thing. Let's say that you've already got your program to look at the current balance (Ending Balance in row 4 of the Account Auction worksheet), and put that value in a variable named Balance; and that you've put the next transaction amount in a variable named XctAmt. Your program is supposed to create a new row in AccountAuction—but before it does, it needs to make sure that there's enough money in the account. That is, once you add a negative transaction amount to a positive balance, the new value should still be positive. In programming there is always more than one way to do that, but the way I choose to demonstrate here goes like this:
If Balance + XctAmt < 0 Then
MsgBox "Error!"
Exit Sub
End If
Note what happens: The program adds Balance and XctAmt, then compares the result to 0. If it's less than 0, then there isn't enough money in the account to cover the transaction, in which case (so say your instructions), you should generate an error message and stop the program.
My error message said simply "Error!", but of course that's not enough information; you'll have to decide just how to word the message to satisfy the requirements of te assignment. After displaying that message is the Exit Sub statement, which stops execution of the subroutine.
If there is enough money in the account, then the program skips over those instructions and just goes on with whatever you tell it to do next, the rest of the program in other words.
If you're "not very good" with VBA then no doubt you'll have other questions, but this should help with the If statement. If it's worse than that—if you've never written anything in VBA before, nor in any other language—then we should back up and proceed one statement at a time, so that you can see what you're building and how each piece works with the rest. But I'll leave it to you to ask the right questions, at first.
|