嗨,我知道有很多問題要求在同一主題,因爲我在這裏,他們似乎並沒有解決我的問題在這裏。 我有一個任務是根據兩張紙的D列比較兩張紙(A和B),我想查找並突出顯示A中不存在的行。 代碼如下所示:找到並突出顯示差異
Dim i As Long
Dim data As Range
Dim ref As Range
Dim lastRow As Long
Worksheets("B").UsedRange
Set ref = Worksheets("test").Columns("D:D").Value
lastRow = Worksheets("B").UsedRange.Rows.Count
Application.ScreenUpdating = False
Application.DisplayAlerts = False
' check if data exist in both shts
For i = 10 To lastRow
Set data = Worksheets("B").Columns("D:D").Find(ref,LookIn:=xlValues, _
LookAt:=xlWhole)
If data Is Nothing Then
data.EntireRow.Interior.ColorIndex = 36
Exit For
Else
End If
Next
現在的問題是,設置ref的行出現所需對象的錯誤,並且行未突出顯示。
screenupdating函數被關閉了一個較短的運行時間,但它仍然需要一些時間來運行我的代碼,這是文件或代碼的問題?
意見將非常感激。
UPDATE使用下面的代碼任務解決:
With Worksheets("test")
For i = 4 To lastRow
For j = 4 To lastnewRow
If Worksheets("test").Cells(i, 9) = Worksheets("B").Cells(j, 9) Then
Exit For
Else
If j = lastnewRow Then
Worksheets("test").Cells(i,9).EntireRow.Interior.ColorIndex = 36
End If
End If
Next
Next
End With
只有在數據不是沒有任何意義的情況下,才嘗試訪問數據的屬性。 –
這是因爲我試圖解決僅存在於表B中的行,代碼是否不正確呢? –
*找到並突出顯示*聽起來像條件格式可能是合適的。 – pnuts