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