我正在尝试清理一些电子表格数据,因此我有下面的代码来删除第10列的数字为0的所有行。问题是当我运行代码时它会删除所有行。
是否有人能够突出我的代码到底出了什么问题?
Sub Format()
Dim Fund As Long
Dim TotalLoop As Long
RowCount = Range("A65536").End(xlUp).Row
For TotalLoop = RowCount To 2 Step -1
Fund = Cells(TotalLoop, 10)
If Fund = 0 Then
Rows(TotalLoop).Delete
Cells(TotalLoop - 1, 10) = Fund
End If
Next TotalLoop
End Sub
答案 0 :(得分:1)
只需删除以下行并执行您的代码即可。它会起作用
Cells(TotalLoop - 1, 10) = Fund
答案 1 :(得分:0)
在您的代码中,您将下一个未删除行的值更改为fund的值,该值为零以便执行代码。删除行Cells(TotalLoop - 1, 10) = Fund
,您的循环将按照需要运行
答案 2 :(得分:0)
子格式()
Dim sh As Worksheet
Dim Fund As Long
Dim TotalLoop As Long
Set sh = ThisWorkbook.Sheets("Sheet1")
RowCount = sh.Range("A1", sh.Range("A1").End(xlDown)).Rows.Count
For TotalLoop = RowCount To 2 Step -1
Fund = Cells(TotalLoop, 10)
If Fund = 0 Then
Rows(TotalLoop).Delete
End If
Next TotalLoop
End Sub