我試圖清理一組數據,並發現一些奇怪的vba功能wholerow.delete 下面的代碼將按預期刪除整行,如果它是採用刪除線格式,但會跳過緊跟其後的行,如果它們也是這種格式。它看起來像一個不是以刪除線格式的行來「重置」刪除更多行的能力。有誰知道爲什麼,或者我能做些什麼來調試呢?「entirerow.delete」跳過For循環的條目
For Each rng In rng1
'Check each character in the cell
For i = 1 To Len(rng.Value)
'If any letter is Strikethrough,delete entire column
If rng.Characters(i, 1).Font.Strikethrough = True Then
rng.Select 'just serves the purpose of observing which rows are being selected
rng.EntireRow.Delete
GoTo NextRng
End If
Next i
NextRng:
Next rng
我應該說,我已經發現使用了不同的方法解決方法,但它是非常緩慢:
'Delete cells that have the strikethrough format - works but is super slow!
ws2.Range("B2").Activate
Do Until ActiveCell.Value = ""
If ActiveCell.Font.Strikethrough = True Then
ActiveCell.EntireRow.Delete
Else: ActiveCell.Offset(1, 0).Activate
End If
Loop
如果任何人有另一種方法來解決這個問題,這也是快速的,我也非常感謝您的意見。
環落後,如果你刪除行。 – Comintern
您不應該像這樣刪除循環中的行。使用反向循環。搜索stackoverflow。我已經在 –
之前回復了一篇文章,請參閱我的[post](http://stackoverflow.com/questions/19241905/vba-conditional-delete-loop-not-working)您還可以使用範圍對象來標識您想要的行刪除。它比刪除循環中的行快得多 –