Unselecting for multiple worksheets in VBA

ukanez

New Member
Joined
Dec 7, 2017
Messages
21
Hello all,

My current macro copies certain sheets over and pastes as values. I'm having problems trying to get each individual work sheet to reset their selection, or at least select cell (1,1).

Code:
Application.ScreenUpdating = False
Sheets(Array("BC", "AB", "SK", "MB", "Prairies", "ON", "QC", "NB", "PE", "NS", "NF", "Atlantic")).Copy
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    ws.Cells.Copy
    ws.Cells.PasteSpecial (xlValues)
    Cells(1, 1).Select
Next

The first sheet in the new file selects cell(1,1) but when I look at the other sheets the selection remains the entire sheet.

Thanks for your help!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi & welcome to the board.
You haven't qualified the cells in the last line of loop so it will always be looking at the active sheet. Try
Code:
ws.Cells(1, 1).Select
 
Last edited:
Upvote 0
Hi & welcome to the board.
You haven't qualified the cells in the last line of loop so it will always be looking at the active sheet. Try
Code:
ws.Cells(1, 1).Select

Thank you. I'm getting a 1004 error that says the Select method of Range class failed. I tried switching that to ws.Range(A1).Select and got the same error. Am I missing something?
 
Upvote 0
Try
Code:
For Each ws In ActiveWorkbook.Worksheets
    ws.activate
    ws.Cells.Copy
    ws.Cells.PasteSpecial (xlValues)
    ws.Cells(1, 1).Select
Next
 
Upvote 0
Thank you very much! Is there any way to add ScrollRow into this code or make each sheet scroll to the top of the page? Having this work properly, I've come to realize that while it selects (1,1), it doesn't actually scroll to the top which is part of why I wanted to select it in the first place.
 
Upvote 0
How about
Code:
For Each ws In ActiveWorkbook.Worksheets
    With ws.UsedRange
        .Value = .Value
    End With
    Application.Goto ws.Cells(1, 1)
Next ws
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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