Rob
Rob

Reputation: 85

VBA: Having Trouble Selecting a Cell in All Worksheets

I have this query that deletes all data in all Worksheets besides the first Row. I'd like to just activate cell "A2" as well on each of these worksheets but can't quite figure it out. Any ideas?

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

Upvotes: 0

Views: 42

Answers (1)

Ralph
Ralph

Reputation: 9434

To summarize the comments:

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

Upvotes: 3

Related Questions