我正在尝试创建一个简单的if语句。当if值不满足else时,这个if语句应移动到else语句,但是excel会给我一个错误13 mismach错误。
这是我的代码:
Sub CALULATE()
Dim postage As String
Dim discountplaceholder As String
discount = Range("d10").Value
If discount = 0.1 Then
MsgBox "hello Bill"
discountplaceholder = 0.1
ElseIf discount = 0.05 Then
MsgBox "hello BOB"
discountplaceholder = 0.05
Else
MsgBox "hello dan"
discountplaceholder = 0
End If
End Sub
第三个单元格值(如果不是0.1或0.05,则为“不适用于折扣”)。有谁知道我怎么能解决这个问题?
提前致谢。
答案 0 :(得分:0)
您要将discountplaceholder
声明为String
,但是您要为其指定Double
类型的值。将discountplaceholder
声明为Double,或为其指定String
。 discountplaceholder = "0.1"
答案 1 :(得分:0)
将Discounterplaceholder
声明为Double
或使用""
为您分配双倍值以将double
转换为literal
Dim discountplaceholder As Double
或
Sub CALULATE()
Dim postage As String
Dim discountplaceholder As String
discount = Range("d10").Value
If discount = "0.1" Then
MsgBox "hello Bill"
discountplaceholder = "0.1"
ElseIf discount = "0.05" Then
MsgBox "hello BOB"
discountplaceholder = "0.05"
Else
MsgBox "hello dan"
discountplaceholder = "0"
End If
End Sub