vba比较两张纸以验证值

时间:2018-06-05 15:34:24

标签: excel vba excel-vba if-statement

我想创建代码,如果列B和A值在CheckList表中, C,D,E列必须在CheckList表中。但是,验证B列和A列是否正常,但C,D,E无法正常工作。

有没有人对此有任何想法?

Private Function rowLast()
    rowLast = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
End Function

Dim rngCell As Range
Dim ValidateL As Long: ValidateL = Sheets("CheckList").Cells(Rows.Count, 1).End(xlUp).Row
For Each rngCell In ActiveSheet.Range("F13:F" & rowLast)
      If WorksheetFunction.CountIf(Sheets("CheckList").Range("B2:B" & ValidateL), rngCell) <> 0 And _
      WorksheetFunction.CountIf(Sheets("CheckList").Range("A2:A" & ValidateL), rngCell.Offset(, -2)) <> 0 And _
      WorksheetFunction.CountIf(Sheets("CheckList").Range("C2:C" & ValidateL), rngCell.Offset(, -1)) = 0 And _
      WorksheetFunction.CountIf(Sheets("CheckList").Range("D2:D" & ValidateL), rngCell.Offset(, 2)) = 0 And _
      WorksheetFunction.CountIf(Sheets("CheckList").Range("E2:E" & ValidateL), rngCell.Offset(, 1)) = 0 Then
       MsgBox "Please validate this combo " & rngCell & " Row Num: " & rngCell.Row
       End
    End If

Next
End Sub

0 个答案:

没有答案