Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA if语句不匹配错误_Excel_Vba_If Statement - Fatal编程技术网

Excel VBA if语句不匹配错误

Excel VBA if语句不匹配错误,excel,vba,if-statement,Excel,Vba,If Statement,我试图创建一个简单的if语句。当值不满足else if时,此if语句应移到else语句,但excel会给出错误13不匹配错误 这是我的密码: 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 ElseI

我试图创建一个简单的if语句。当值不满足else if时,此if语句应移到else语句,但excel会给出错误13不匹配错误

这是我的密码:

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
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)不适用于折扣。有人知道我怎么解决这个问题吗

提前谢谢

您将折扣占位符声明为字符串,但随后将为其指定一个Double类型的值。将折扣占位符声明为双精度,或为其指定字符串。折扣占位符=0.1

将折扣占位符声明为双精度占位符,或在为其指定双精度值时使用,以将双精度转换为文字

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