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
 
Your count should really start at 4, since you already have the third sheet selected.
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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
 
Upvote 0
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?
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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