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
VBA类型不匹配的错误(错误13)_Vba_Excel_Type Mismatch - Fatal编程技术网

VBA类型不匹配的错误(错误13)

VBA类型不匹配的错误(错误13),vba,excel,type-mismatch,Vba,Excel,Type Mismatch,我的代码: Sub sem() Dim f As Variant Dim f1 As Long Dim F2 As Long f = Format(DTPFechaFalla, "yyyymmdd") f1 = 20141227 F2 = 20150124 If (f >= f1) & (f <= F2) Then Week = 1 month = 1 Else MsgBox "Fale" End If

我的代码:

Sub sem()
Dim f As Variant
Dim f1 As Long
Dim F2 As Long

f = Format(DTPFechaFalla, "yyyymmdd")
f1 = 20141227
F2 = 20150124


    If (f >= f1) & (f <= F2) Then
       Week = 1
       month = 1
    Else
       MsgBox "Fale"
    End If

End Sub
Sub-sem()
作为变体的dimf
将f1调暗为长
将F2变长
f=格式(DTPFechaFalla,“yyyymmdd”)
f1=20141227
F2=20150124

如果(f>=f1)和(f
If(f>=f1)和(f=f1)和(f变量f的声明是variant。但是,如果调用format函数,结果将转换为字符串。然后,您需要将long类型的f1与字符串进行比较。这就是问题所在。在调用format函数之前,请将f与f1进行比较。

在哪一行上类型不匹配?这不是问题-某些隐式转换将发生例如,
?20141229
?20141227
If (f >= f1) & (f <= F2) Then
If (f >= f1) And (f <= F2) Then