Private Sub cbo_Loc_Change()
Dim Date1 As Date
Dim Row As Integer
Row = ActiveCell.Row
If cbo_Loc.Value = TDS Then
Date1a = Cells(Row, 5).Value
T1a = DateAdd("ww", 6, Date1a)
Cells(Row, 6).Formula = T1a
T1b = DateAdd("ww", 8, Date1a)
Cells(Row, 7).Formula = T1b
ElseIf cbo_Loc.Value = SS Then
T1a = DateAdd("M", 18, Date1a)
Cells(Row, 6).Formula = T1a
T2b = DateAdd("m", 6, Date1a)
Cells(Row, 7).Formula = T1b
End If
End Sub
上述If-Else语句应该在满足if条件时添加6和8周到date1a,并且如果满足条件则添加18和24个月到date1a。当满足ElseIf条件时,其下的语句不会发生。任何人都可以看看它,找出可能存在的问题。
谢谢,
答案 0 :(得分:0)
您需要为ElseIf语句设置“Date1a”的值,因为当If语句被评估为false时,ElseIf语句将不会赋值为“Date1a”。你可以通过以下方式之一做到这一点:
Private Sub cbo_Loc_Change()
Dim Date1 As Date
Dim Row As Integer
Row = ActiveCell.Row
If cbo_Loc.Value = TDS Then
Date1a = Cells(Row, 5).Value
T1a = DateAdd("ww", 6, Date1a)
Cells(Row, 6).Formula = T1a
T1b = DateAdd("ww", 8, Date1a)
Cells(Row, 7).Formula = T1b
ElseIf cbo_Loc.Value = SS Then
Date1a = Cells(Row, 5).Value
T1a = DateAdd("M", 18, Date1a)
Cells(Row, 6).Formula = T1a
T2b = DateAdd("m", 6, Date1a)
Cells(Row, 7).Formula = T1b
End If
End Sub
或
Private Sub cbo_Loc_Change()
Dim Date1 As Date
Dim Row As Integer
Row = ActiveCell.Row
Date1a = Cells(Row, 5).Value
If cbo_Loc.Value = TDS Then
T1a = DateAdd("ww", 6, Date1a)
Cells(Row, 6).Formula = T1a
T1b = DateAdd("ww", 8, Date1a)
Cells(Row, 7).Formula = T1b
ElseIf cbo_Loc.Value = SS Then
T1a = DateAdd("M", 18, Date1a)
Cells(Row, 6).Formula = T1a
T2b = DateAdd("m", 6, Date1a)
Cells(Row, 7).Formula = T1b
End If
End Sub
任何一个都可以解决你的问题。