vba 选择最后一行并清除内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23127936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Select last row and clears content
提问by Nicholas Agius
I have the following sheet in which user input data.
我有以下用户输入数据的工作表。
https://dl.dropboxusercontent.com/u/83126653/user%20form%201.png
https://dl.dropboxusercontent.com/u/83126653/user%20form%201.png
Now I am using this code to delete the last row
现在我正在使用此代码删除最后一行
Sub DeleteLastRow()
Sheets("User Form Engine data 1 Entry").UsedRange. _
Range("A2:K2").End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).ClearContents
End Sub
I would like to clear all the last row if even one cell from the row has something in it. need help. Thanks in advance
如果行中的一个单元格中有内容,我想清除所有最后一行。需要帮忙。提前致谢
采纳答案by brettdj
Try using Find
to find the last row. It is more robust than the xlDown
and xlUp
approaches (see Return a range from A1 to the true last used cell)
尝试使用Find
查找最后一行。它比xlDown
和xlUp
方法更健壮(请参阅返回从 A1 到真正上次使用的单元格的范围)
Last row in columns A:K to be deleted
要删除 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
Last row in worksheet to be deleted
要删除的工作表中的最后一行
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