sammclean23
11-22-2011, 10:00 AM
Hi All,
I'm very nearly there but just don't seem to be able to get the last bit to function correctly.
Basically, the user enters 'x' amount of numbers through the use of a form i.e. a number is typed into a text box and upon clicking 'enter' the value is added to the spreadsheet starting from A1 using an offset.
The final part is calculating the total of these numbers and displaying that total on the next available row. To do this, the user will click 'checkout' on the form.
I understand this is simple VBA but just can't succeed on this last bit. Im guessing I have to create a running total because there is no specific amount of numbers its not a case of "=sum(a1:a5)" for example.
I appreciate any help on this. Also, if setting the 'total' variable for cmdEnter, would I have to set it again for cmdCheckout to work?
The code I have so far is this:
Private Sub cmdCheckout_Click()
Dim Total As Double
Total = Total + txtPrice
ActiveCell.Value = Total
End Sub
Private Sub cmdEnter_Click()
ActiveCell.NumberFormat = "£0.00"
ActiveCell.Value = txtPrice.Text
ActiveCell.Offset(1, 0).Activate
txtPrice.Text = ""
txtPrice.SetFocus
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_Initialize()
Range("A1").Select
'Ensures range a1 is selected upon opening
End Sub
I'm very nearly there but just don't seem to be able to get the last bit to function correctly.
Basically, the user enters 'x' amount of numbers through the use of a form i.e. a number is typed into a text box and upon clicking 'enter' the value is added to the spreadsheet starting from A1 using an offset.
The final part is calculating the total of these numbers and displaying that total on the next available row. To do this, the user will click 'checkout' on the form.
I understand this is simple VBA but just can't succeed on this last bit. Im guessing I have to create a running total because there is no specific amount of numbers its not a case of "=sum(a1:a5)" for example.
I appreciate any help on this. Also, if setting the 'total' variable for cmdEnter, would I have to set it again for cmdCheckout to work?
The code I have so far is this:
Private Sub cmdCheckout_Click()
Dim Total As Double
Total = Total + txtPrice
ActiveCell.Value = Total
End Sub
Private Sub cmdEnter_Click()
ActiveCell.NumberFormat = "£0.00"
ActiveCell.Value = txtPrice.Text
ActiveCell.Offset(1, 0).Activate
txtPrice.Text = ""
txtPrice.SetFocus
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_Initialize()
Range("A1").Select
'Ensures range a1 is selected upon opening
End Sub