我有以下用户输入数据表。
https://dl.dropboxusercontent.com/u/83126653/user%20form%201.png
现在我使用此代码删除最后一行
Sub DeleteLastRow()
Sheets("User Form Engine data 1 Entry").UsedRange. _
Range("A2:K2").End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).ClearContents
End Sub
如果行中的一个单元格中有内容,我想清除所有最后一行。需要帮忙。提前致谢
答案 0 :(得分:2)
尝试使用Find
查找最后一行。它比xlDown
和xlUp
方法更强大(参见Return a range from A1 to the true last used cell)
A列中的最后一行:要删除的K
Sub KillLast()
Dim ws As Worksheet
Dim rng1 As Range
Set ws = Sheets("User Form Engine data 1 Entry")
Set rng1 = ws.Range("A:K").Find("*", ws.[a1], xlValues, , xlByRows, xlPrevious)
If Not rng1 Is Nothing Then rng1.EntireRow.Delete
End Sub
要删除的工作表中的最后一行
Sub KillLast()
Dim ws As Worksheet
Dim rng1 As Range
Set ws = Sheets("User Form Engine data 1 Entry")
Set rng1 = ws.UsedRange.Find("*", ws.[a1], xlValues, , xlByRows, xlPrevious)
If Not rng1 Is Nothing Then rng1.EntireRow.Delete
End Sub