+ Reply to Thread
Results 1 to 5 of 5

End Script on worksheet that it was started in?

Hybrid View

  1. #1
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    End Script on worksheet that it was started in?

    Hi Everyone,

    I have a workbook with about 52 worksheets, I have a script that will unlock the protection from all the worksheets. However the problem I'm having is the script runs and starts and ends at sheet1 I want the script to start and end at the sheet I run the script from lets say sheet 40?

    Here is what I have now.

    Any Ideas?

    Thank You for your help!!!
    Mike

    Sub unProtect()
    
    Dim Wks As Worksheet
    
        For Each Wks In Worksheets
    
            On Error Resume Next
    
            Wks.Select: Wks.Activate
    
            Wks.unProtect "Leith"
            
        Next Wks
    
    
    End Sub
    Last edited by realniceguy5000; 11-10-2008 at 11:26 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Sub unProtect()
        Dim wks As Worksheet
    
        For Each wks In Worksheets
            wks.unProtect "Leith"
        Next wks
        Worksheets(1).Select
    End Sub
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951
    Thank You... But...

    I understand your change however what I want to happen is if I start the script on sheet 40 I want the script to end on sheet 40 or whatever sheet the script was started on?

    How to change to make that happen?


    Thank You Again...

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    Would this work?
    ' Remember where you were (near the top of your code)
            Dim rStartCell As Range
            Set rStartCell = ActiveCell
    
    [the rest of your code]
    
    ' Go back to where you were (at the bottom of your code)
            Application.Goto rStartCell
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951
    Yes that works great... Thank You for your help, Mike

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1