Excel – 运行时错误13:types不匹配?
我有一个Excel窗体的问题,我不明白。 该表格有2个date字段的开始和结束date和1个名为固定期限的CHeckbox。
目标是当checkbox被选中的时期是1年,因此结束date重新计算Begindate作为基地。 下面的VBA代码在If语句中导致错误13types不匹配。
我认为date应该用CDate进行转换,或者是否是这个问题? 任何指针赞赏
Private Sub BeginDatum_Change() Static OldValue As String With Me.BeginDatum Debug.Print "Value: "; .Value; " Old Value: "; OldValue If CDate(.Value) > CDate(EindDatum.Value) Or CDate(.Value) > Date Then Debug.Print "EindDatum " & EindDatum.Value & " is NOT Good" .Value = OldValue Else Sheets("Traject").Range("Begin") = .Value OldValue = .Value If (FixedPeriod) Then EindDatum.Value = Format(DateAdd("yyyy", 1, Me.BeginDatum.Value), "dd/mm/yyyy") End If End If End With End Sub
其中一个最终不是约会或不可能转换到date。
- CDATE(.value的)
- CDATE(EindDatum.Value)
- CDATE(.value的)
在尝试转换之前,您需要确定input是否代表有效的date。
If IsDate(.Value) then 'use the input End if
等等…
则IsDate