我想找出一个代码来删除“C”列中复制数据的最后一行之后的所有行。
因此,假设我在C列中的数据在第1265行结束,代码假设在此之后删除所有行..
由于
答案 0 :(得分:2)
您可以尝试这样的事情......
Sub DeleteRows()
Dim LastRowColC As Long, LastRow As Long
LastRow = ActiveSheet.UsedRange.Rows.Count
LastRowColC = Cells(Rows.Count, "C").End(xlUp).Row
If LastRow > LastRowColC Then
Rows(LastRowColC + 1 & ":" & LastRow).Delete
'OR
'Rows(LastRowColC + 1 & ":" & LastRow).Clear
End If
End Sub
如果数据在Excel表中,请尝试这样......
Sub DeleteRows()
Dim LastRowColC As Long, LastRow As Long
Dim tbl As ListObject
Set tbl = ActiveSheet.ListObjects(1)
LastRow = tbl.DataBodyRange.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
LastRowColC = tbl.DataBodyRange.Columns(3).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If LastRow > LastRowColC Then
Rows(LastRowColC + 1 & ":" & LastRow).Delete
End If
End Sub