Worksheets(x).Select Error

aadil_1408

New Member
Joined
Jan 3, 2021
Messages
16
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I am trying to select multiple sheets using the following code.

VBA Code:
    Dim x As Integer
    ThisWorkbook.Worksheets(3).Select
    For x = 3 To ThisWorkbook.Worksheets.count
        Worksheets(x).Select (False)
    Next x

Although it is a common code it does not work with the later versions of excel as other people online have encountered similar issues. Is there another way to selects all sheets except first two?

Thanks and Regards,
Aadil Khan
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,730
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Your count should really start at 4, since you already have the third sheet selected.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

aadil_1408

New Member
Joined
Jan 3, 2021
Messages
16
Office Version
  1. 2019
Platform
  1. Windows
Does it work when you comment out the same lines that I did, i.e. the path and the saveas lines?
Do you have any protection either on the Workbook or the Worksheets?
Does it work when you comment out the same lines that I did, i.e. the path and the saveas lines?
no it does not
Do you have any protection either on the Workbook or the Worksheets?
No i do not
The sheets are all visible aren't they?
Yes they are all visible
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,066
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
With Rory's code when the code errors and you hover your mouse over the v in the highlighted line what does it show? and have you changed it to 4 as Rory has suggested?
 

aadil_1408

New Member
Joined
Jan 3, 2021
Messages
16
Office Version
  1. 2019
Platform
  1. Windows
With Rory's code when the code errors and you hover your mouse over the v in the highlighted line what does it show? and have you changed it to 4 as Rory has suggested?
Ya it worked Rory, Thanks a lot. When I hovered over it showed outta range. That was a careless mistake from my part. Sorry for wasting your time on this. I appreciate the solutions that you have sent me and thanks for your time.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,207
Messages
5,640,848
Members
417,173
Latest member
Tuanphun

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
Top