VBA code to run on specific sheet numbers

valmir

Board Regular
Joined
Feb 10, 2021
Messages
217
Office Version
  1. 365
Platform
  1. Windows
Hi everyone.
I understand that this part of the VBA Code
Dim i As Long
For i = 1 To 14
Sheets(i).Activate
means it will run all all sheets from 1 to 14.
What if I want it to run on specific sheet numbers, for example: 1 to 3; 5 to 7 and 9 or else, is there a way to skip some sheet numbers, like run from 1 to 14 except 3, 8 and 9 for example?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
You could use something like
VBA Code:
   Dim i As Long
   For i = 1 To 14
      Select Case i
         Case 1 To 3, 5 To 7, 9
         Sheets(i).Select
      End Select
   Next i
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,203,242
Messages
6,054,349
Members
444,717
Latest member
melindanegron

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