So I'm new to programing(2weeks). I am making a data box to find total a price for a project. I works with text boxes, check boxes and a button to find total.
I input the number of lemons and oranges, when I press the button it calculates how much it will cost based on prices that are pulled from the sheet.
Now I put the check box because there is a set quantity of one. I would like to add the price of "sugar" to the total price when it is checked.
Can some one help me get the check box add to total price?
for example the data box looks like this: Thanks enter image description here
New code almost works the way I was hoping. thank you for the advice, I tried referencing the sheet and it gave me errors. But it works like this for now.
-When I input numbers in the input boxes and press calculate it gives me the correct total. -When I check the check box it adds to the total, BUT when I press "Calc" the total is calculated without including checked box. -When I press more then one checkbox for example: Select "Checksugar" then "checkbox2" the total only adds the value of "Checkbox2". then when I press "Calc" again, the total ignores the checkboxes.
What im wanting it do: When I select more then one check box, I want the totals to add rather then replace eachother. I also want the code to give the total value when I press "Calc" rather then only the totals of the input boxes.
What I think I need to do: Some how add the If statements in the "TxtTotal", but I do not know how to do that. Or have multiple If statements.
Can someone help?
Private Sub Calculate_Click()
TxtTotal = TxtLemon * Range("E21").Value + TxtLime * Range("E20").Value _ + TxtOranges * Range("E19").Value _ + TxtApple * Range("E25").Value _ + TxtCactus * Range("E24").Value
End Sub
Private Sub Checksugar_Click() If Me.Checksugar.Value = True Then
TxtTotal = TxtLemon * Range("E21").Value + TxtLime * Range("E20").Value _
+ TxtOranges * Range("E19").Value _ + TxtApple * Range("E25").Value _ + TxtCactus * Range("E24").Value + Range("E22").Value
End If End Sub
Private Sub Checkbox2_Click() If Me.Checkbox2.Value = True Then
TxtTotal = TxtLemon * Range("E21").Value + TxtLime * Range("E20").Value _ + TxtOranges * Range("E19").Value _ + TxtApple * Range("E25").Value _ + TxtCactus * Range("E24").Value + Range("E27").Value
End If End Sub