-
Feb 25th, 2012, 08:43 PM
#1
Thread Starter
New Member
[RESOLVED] Excel 2007 IF statement Issue
Hi, this is my first post. I am new to visual basic. I built a small applet to handle transactions (Debits and Credits on excel) the credit function allows the user to input the credit amount and then the code updates all relevant cells on the spreadsheet and works out a closing balance.
What I would like to do for the credit function is
1. have a check that works out whether the credit amount will take the user into a negative figure.
2. if yes then display a message box warning the user and asking them if they want to continue.
3. if yes then update the spreadsheet fields.
4. if no then end.
I tried doing an if statement but it will only run whatever if i put first i.e. "if vbno then end" is the first statement it will only run this regardless of what button is pressed.
The code i have used is:
Private Sub CommandButton3_Click()
Dim Opening As Double
Dim Credit
Dim Continue As VbMsgBoxResult
Dim TranType As String
Dim Closing As Double
Dim Time As Date
Credit = InputBox("Enter Credit Amount", "Credit Function")
If IsNumeric(Credit) = False Then
Continue = MsgBox("Incorrect Value Entered", , "Credit Function")
ElseIf IsNumeric(Credit) = True Then
Opening = Range("D80000").End(xlUp).Value
Range("A80000").End(xlUp).Offset(1, 0).Value = Opening
Range("B80000").End(xlUp).Offset(1, 0).Value = Credit
Closing = Opening - Credit
Range("D80000").End(xlUp).Offset(1, 0).Value = Closing
TranType = "Out"
Range("C80000").End(xlUp).Offset(1, 0).Value = TranType
Time = Date
Range("E80000").End(xlUp).Offset(1, 0).Value = Time
transaction.TextBox3 = Credit
transaction.TextBox1 = Closing
transaction.TextBox4.Text = Format(Date, "dd/mm/yyyy")
End If
End Sub
Thanks in advance for any help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|