【发布时间】:2019-05-17 07:16:04
【问题描述】:
我是一名学生,不熟悉 VBA 编码和编程。我需要创建一个代码来评估 3 个 if 语句,并根据 if 语句的标准在我们正在使用的数据库中填充一个单元格值(给定折扣)。我已经创建了用户表单来输入客户 ID、客户名称、销售价值和出生日期。我遇到的问题是我需要根据以下内容创建一个 If 语句:
1) 如果客户出生时间早于 1960 年 1 月 5 日,他们的折扣应该是销售额的 10%(在给定的折扣列中应该只显示数字 - 而不是文本)
2) 如果客户出生于 1980 年 1 月 20 日之后,他们的折扣应该是 5% 销售价值(只有数字应该显示在给定的折扣列中 - 不是文本)
3) 对于所有其他出生日期不同的客户,他们的折扣应为 2%(因此 > 1/5/1960 和
我插入了我在下面编写的代码,但它似乎不起作用我希望有人可以帮助我。
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
【问题讨论】:
-
代码的哪一部分不起作用?它在做什么呢?
标签: excel vba if-statement excel-formula userform