VBA:在所有工作表中选择单元格时遇到问题

时间:2016-06-06 17:53:52

标签: excel vba excel-vba

我有这个查询删除除第一行之外的所有工作表中的所有数据。我想在每个工作表上激活单元格“A2”,但不能完全理解它。有什么想法吗?

Sub ClearWorkbook()
    Dim Current As Worksheet
    For Each Current In Worksheets
        Current.Rows("2:" & Rows.Count).ClearContents
    Next
End Sub

1 个答案:

答案 0 :(得分:3)

总结评论:

Sub ClearWorkbook()

Dim Current As Worksheet

For Each Current In Worksheets
    If Current.Cells(Current.Rows.Count, "A").End(xlUp).Row >= 2 Then
        Current.Rows("2:" & Current.Cells(Current.Rows.Count, "A").End(xlUp).Row).ClearContents
    End If
    Current.Activate
    Current.Range("A2").Select
Next

End Sub