VBA to select specific worksheets to run a macro

I need to use VBA to run a macro but to only run the macro for the worksheets that I have flagged in an administration sheet.
If when working down the list of worksheets a sheet is not present the macro will simply go to the next sheet on the list
The worksheet list is constantly being changed, increased and decreased
Selective-macro-application.xlsm
DAVID131Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Glenn RayExcel VBA DeveloperCommented:
Here is code that will achieve this selective method:
Option Explicit
Sub Run_Selective()
    Dim rng As Range
    Dim cl As Object
    Dim boolError As Boolean
    
    Sheets("Administration").Select
    Set rng = Range("A1", Range("A1").End(xlDown))
    
    For Each cl In rng
        If cl.Offset(0, 1).Value = "yes" Then
            On Error GoTo NoSheet
            boolError = False
            Sheets(cl.Value).Activate
            If Not (boolError) Then SIMPLE_COPY_TEST
        End If
    Next cl
    MsgBox "Done."
    Exit Sub
    
NoSheet:
    boolError = True
    Resume Next

End Sub

Open in new window


I've also attached a modified version of your workbook for you to test.  I tweaked the SIMPLE_COPY_TEST subroutine also to better work with the code.

Regards,
-Glenn
EE-Selective-macro-application.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DAVID131Author Commented:
Thanks Glenn
Spot on piece of VBA - DOES EXACTLY WHAT WAS ASKED AND SAVES A LOT OF MANUAL WORK

Regards
David
Edinburgh
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.