好吧,我在一分钟前解决了一个小问题,但现在我的宏上有另一个问题:(
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim S1 As String, S2 As String
Dim S3 As String, S4 As String
Dim lRow As Long, i As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
S1 = "Football"
S2 = "Basket"
S3 = "Sport1"
S4 = "Sport2"
With ws
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 1 To lRow
If Len(Trim(.Range("E" & i).Value)) = 0 Then
Select Case .Range("C" & i).Value
Case S1, S2
MsgBox "Insert value in the cell " & _
.Range("E" & i).Address
Cancel = True
Exit For
End Select
End If
If (Len(Trim(.Range("F" & i).Value)) = 0) Or _
(Len(Trim(.Range("G" & i).Value)) = 0) Or _
(Len(Trim(.Range("H" & i).Value)) = 0) Then
Select Case .Range("C" & i).Value
Case S3, S4
MsgBox "Insert value in the cell " & _
.Range("F" & i).Address, _
.Range("G" & i).Address, _
.Range("H" & i).Address
Cancel = True
Exit For
End Select
End If
Next i
End With
End Sub
第一个if
有效,但第二个
If (Len(Trim(.Range("F" & i).Value)) = 0) Or _
(Len(Trim(.Range("G" & i).Value)) = 0) Or _
(Len(Trim(.Range("H" & i).Value)) = 0) Then
Select Case .Range("C" & i).Value
Case S3, S4
MsgBox "Insert value in the cell " & _
.Range("F" & i).Address, _
.Range("G" & i).Address, _
.Range("H" & i).Address
Cancel = True
Exit For
End Select
End If
没有。有什么不对?
如您所见,条件相同,但在不同的列中