What's the best way to select cell A1 in all sheets in the this workbook using VBA?

xcelnovice101

Active Member
Joined
Aug 24, 2012
Messages
368
Below is my code for deleting all data in all of the sheets in ThisWorkbook, but I also want to select cell A1 in all sheets in ThisWorkbook. The code does fin until it comes to select cell A1 on the second sheet.

Code:
Sub CLEAR_FS_MTD_REPORT()
    Sheets(1).Name = "Sheet1"
    Sheets(2).Name = "Sheet2"
    Dim ws As Worksheet
        For Each ws In ThisWorkbook.Worksheets
            ws.Cells.Delete Shift:=xlUp
        Next ws
    Dim wss As Worksheet
        For Each wss In ThisWorkbook.Worksheets
            wss.[A1].Select
        Next wss
    Sheets(1).Select
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Put this line:
Code:
wss.Activate
below this line:
Code:
For Each wss In ThisWorkbook.Worksheets
 
Upvote 0
I've edited my code to the following and it still doesn't select A1 on any other sheet other than the first one.

Code:
Sub CLEAR_FS_MTD_REPORT()
    Sheets(1).Name = "Sheet1"
    Sheets(2).Name = "Sheet2"
    Dim ws As Worksheet
        For Each ws In ThisWorkbook.Worksheets
            ws.Cells.Delete Shift:=xlUp
            [A1].Activate
        Next ws
    Sheets(1).Select
End Sub
 
Upvote 0
Got it figured out.

Code:
Sub CLEAR_FS_MTD_REPORT()
    Sheets(1).Name = "Sheet1"
    Sheets(2).Name = "Sheet2"
    Dim ws As Worksheet
        For Each ws In ThisWorkbook.Worksheets
            ws.Select
            Cells.Delete Shift:=xlUp
            Range("A1").Select
        Next ws
    Sheets(1).Select
End Sub
 
Upvote 0
Just remove this part of the original code,
Code:
Next ws
    Dim wss As Worksheet
        For Each wss In ThisWorkbook.Worksheets
and change this,
Code:
   wss.[A1].Select
Next wss

to this.
Code:
   Application.Goto ws.Range("A1"), True

Next ws
 
Upvote 0
sub SelectA1 ()
For i = 1 to Sheets.count
Sheets(i).Range("a1").select
Next i
end sub
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,643
Members
449,093
Latest member
Ahmad123098

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top