I am a student and new to VBA coding and programing. I need to create a code that will asses 3 if statement and based on the criteria of the if statements a cell value (discount given) will populate in the database we are working with. I have already created the userform to input a customer ID, customer name, sales value and DOB. The issue I am having is that I need to create an If statement based on the following:
1) If the customer was born earlier than 1/5/1960, their discount should be 10% of the sales value (only numbers should show up in the discount given column - not text)
2) If the customer was born after 1/20/1980, their discount should be 5% of the sales value (only numbers should show up in the discount given column - not text)
3) For all other customers, born on a different date, their discount should be 2% (so > 1/5/1960 and < 1/20/1980), (only numbers should show up in the discount given column - not text).
I inserted the code I wrote below, but it doesn't seem to be working I am hoping someone can help me.
[Private Sub CommandButton1_Click()
discount = Range("F8").Value
Rows(8).Insert Copyorigin:=xlFormatFromRightOrBelow
Range("B8").Value = TextBox1.Text
Range("C8").Value = TextBox2.Text
Range("D8").Value = TextBox3.Text
Range("E8").Value = TextBox4.Text
Range("F8").Value = discount
If discount < 1 / 5 / 1960 Then result = Range("D8").Value * 0.1 Else
If discount > 1 / 20 / 1980 Then result = Range("D8").Value * 0.05 Else
If discount > 1 / 5 / 1960 & discount < 1 / 20 / 1980 Then result =
Range("D8").Value * 0.02
End If
End If
End If
Unload Me
End Sub][1]
https://i.stack.imgur.com/dC4CP.jpg
Aucun commentaire:
Enregistrer un commentaire