VBA/Macro 使用 "only formula" 删除整行
VBA/Macro to delete entire row with "only formula"
如何删除 A 列中仅包含公式的所有行?我需要删除它,这样我就不会在选择范围或录制宏时遇到问题。
我试过了:
Selection.AutoFilter
ActiveSheet.Range("$A:$L").AutoFilter Field:=1, Criteria1:="#REF!"
Rows("720:720").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=-27
ActiveSheet.Range("$A:$L9").AutoFilter Field:=1
和:
Dim c As Range
Dim SrchRng
Set SrchRng = ActiveSheet.Range("A1", ActiveSheet.Range("A1000000").End(xlUp))
Do
Set c = SrchRng.Find("=+LEFT(#REF!,2)", LookIn:=xlValues)
If Not c Is Nothing Then c.EntireRow.delete
Loop While Not c Is Nothing
但没有任何效果。我试图删除所有具有 #REF
或公式本身 "=+LEFT(#REF!,2)"
的行,但仍然没有成功。
我需要删除只有公式的 all/entire 行。这些公式在Column A
请看下面的代码
Sub DeleteFormulaCells()
lastrow = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To lastrow
If Range("A" & i).HasFormula() = True Then
Rows(i).EntireRow.Delete
lastrow = lastrow - 1
End If
Next i
End Sub
试试这个
Sub DeleteRowsWithFormulas()
ActiveSheet.Columns("A").SpecialCells(xlCellTypeFormulas).EntireRow.Delete
End Sub
如何删除 A 列中仅包含公式的所有行?我需要删除它,这样我就不会在选择范围或录制宏时遇到问题。
我试过了:
Selection.AutoFilter
ActiveSheet.Range("$A:$L").AutoFilter Field:=1, Criteria1:="#REF!"
Rows("720:720").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=-27
ActiveSheet.Range("$A:$L9").AutoFilter Field:=1
和:
Dim c As Range
Dim SrchRng
Set SrchRng = ActiveSheet.Range("A1", ActiveSheet.Range("A1000000").End(xlUp))
Do
Set c = SrchRng.Find("=+LEFT(#REF!,2)", LookIn:=xlValues)
If Not c Is Nothing Then c.EntireRow.delete
Loop While Not c Is Nothing
但没有任何效果。我试图删除所有具有 #REF
或公式本身 "=+LEFT(#REF!,2)"
的行,但仍然没有成功。
我需要删除只有公式的 all/entire 行。这些公式在Column A
请看下面的代码
Sub DeleteFormulaCells()
lastrow = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To lastrow
If Range("A" & i).HasFormula() = True Then
Rows(i).EntireRow.Delete
lastrow = lastrow - 1
End If
Next i
End Sub
试试这个
Sub DeleteRowsWithFormulas()
ActiveSheet.Columns("A").SpecialCells(xlCellTypeFormulas).EntireRow.Delete
End Sub