【发布时间】:2015-03-18 17:55:18
【问题描述】:
我正在尝试运行一个小宏来搜索工作表的 S 列,如果 S 列中的值
我目前正在运行的代码删除了一些行,但似乎是随机删除的,而不是基于 s 中的单元格值。谁能看到我的错误来自哪里?
Sub sort_delete_500cust()
Dim WS_Count As Integer
Dim I, K As Integer
Dim endrow As Long
' Set WS_Count equal to the number of worksheets in the active
' workbook.
WS_Count = Workbooks("Standard.xlsx").Worksheets.count
' Begin the loop.
For I = 1 To WS_Count
With Worksheets(I)
endrow = .Range("a" & .Rows.count).End(xlUp).row ' only works if cells are unmerged
Range("A2:v2" & endrow).Sort _
Key1:=Range("s2"), Order1:=xlDescending 'key is the sort by column
For K = 2 To endrow
If .Cells(K, 19).Value < 0.501 Then
.Range("S" & K).EntireRow.Delete
End If
Next K
End With
Next I
End Sub
干杯!
【问题讨论】:
-
专业提示,@pnuts。删除时,始终从底部开始,一直到顶部。
-
干杯@pnuts。我会花一些时间来弄清楚 o_O
标签: vba excel if-statement delete-row