1
我創建了一個VBA,它將比較兩張相同的Excel文件。如果工作表A中的數據不準確,它會將該行的顏色更改爲紅色,如果我的顏色發生更改,我也應用了過濾器。VBA - 用於比較兩列的Excel
現在的問題是它沒有以適當的方式工作。就像我的數據相同,那麼它也是應用過濾器。
見我下面
Sub Validate_Metadata()
Dim myRng As Range
Dim lastCell As Long
Dim flag As Boolean
'Get the last row
Dim lastRow As Integer
lastRow = ActiveSheet.UsedRange.Rows.Count
'Debug.Print "Last Row is " & lastRow
Dim c As Range
Dim d As Range
Application.ScreenUpdating = False
For Each c In Worksheets("Sheet1").Range("A2:A" & lastRow).Cells
For Each d In Worksheets("Sheet2").Range("A2:A" & lastRow).Cells
c.Interior.Color = vbRed
flag = False
If (InStr(1, d, c, 1) > 0) Then
c.Interior.Color = vbWhite
Exit For
End If
Next
Next
If (flag <> True) Then
ActiveSheet.Range("A1:A" & lastRow).AutoFilter Field:=1, Criteria1:=RGB(255, 0 _
, 0), Operator:=xlFilterCellColor
End If
Application.ScreenUpdating = True
End Sub
感謝