我使用,我是在這之前的問題幫助該代碼:(VBA Excel find and replace WITHOUT replacing items already replaced)Excel的VBA運行時錯誤:對象「內部」的方法,「色」失敗
我有下面的代碼,我用它來取代在物品欄: 子Replace_Once() Application.ScreenUpdating =假
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Range("A1:A" & LastRow).Interior.ColorIndex = xlNone
For Each Cel In Range("B1:B" & LastRow)
For Each C In Range("A1:A" & LastRow)
If C.Value = Cel.Value And C.Interior.Color <> RGB(200, 200, 200) Then
C.Interior.Color = RGB(200, 200, 200)
C.Value = Cel.Offset(0, 1).Value
End If
Next
Next
這對於小文件工作正常,但是當A列的長度接近3800和B和C是約280 Excel的崩潰,我得到出現以下錯誤:
Run-time error '-2147417848 (800810108)':
Method 'Color' of object "Interior' failed
任何想法爲什麼會發生這種情況?
編輯:只是爲了澄清錯誤似乎在該行
If C.Value = Cel.Value And C.Interior.Color = RGB(200, 200, 200) Then
我跑用10作爲LASTROW數你的代碼,其運行沒有任何問題。把一些錯誤陷阱,以獲得完整的錯誤 – Sorceri
它運行正常,10作爲LastRow的數字,但錯誤開始出現時,數字接近3800 – genuinelycurious
我跑到4000,它很好。可能是工作簿的一個問題。將數據複製到記事本中,然後回到excel中。重新運行宏。如果失敗,嘗試使用GUI手動設置單元格的顏色。你有沒有陷入錯誤?示例:出錯goto captureError captureError:如果Err.Number> 0,那麼msgbox Err.Description – Sorceri