@IAmDranged正確的是,當您刪除一行時,下一行將向上移動併成爲當前行。 Next cell
行然後將通過此行並移動到下一行,而不檢查是否有任何單元格的長度小於2個字符。
這裏的另一個方法是將離開Delete
方法,直到少於2個字符後,將細胞已被發現:
Sub way()
Dim cell As Range
Dim deleteRange As Range 'This will be used to store the Cells found
Range("A1").CurrentRegion.Activate
For Each cell In Selection
If Len(cell) < 2 Then
If deleteRange Is Nothing Then
' If this is the first cell found, then Set deleteRange to this cell
Set deleteRange = cell
Else
' Any cells found after the first, we can use the
' Union method to add it to the deleteRange
Set deleteRange = Application.Union(cell, deleteRange)
End If
End If
Next cell
' Once all cells have been found, then Delete
deleteRange.Delete
End Sub
你是什麼意味着你可以在沒有線的情況下運行它?沒有哪一行? –
範圍(「A1」)線。 – connor
喬治,你是怎麼把代碼放在灰色的盒子裏的?謝謝 – connor