+ Reply to Thread
Results 1 to 2 of 2

VBA to go back to original worksheet one started with

  1. #1
    Registered User
    Join Date
    11-21-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    9

    VBA to go back to original worksheet one started with

    I have multiple work sheets I will be working from at random. As I need theses sheets to stay protected it makes thing harder.
    Such as; copy and paste from one sheet to another. I need the macro to unprotect sheet, copy the selected info, paste it to another sheet. Not so difficult.

    Problem is getting the macro to go back and protect the original sheet I copied from. This sheet is at random. I may need to copy from Sheet1 to the TEST Sheet or from Sheet119 to the TEST Sheet… Either way I don’t know how to get the macro to go back to the sheet I copied from.

    I heard the code me.sheets tells the macro what sheet it’s starting from, but I can’t get it to work. The below formula is my attempt to get it to work. Please help.




    Please Login or Register  to view this content.
    Last edited by D_Step; 11-30-2012 at 07:55 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,696

    Re: VBA to go back to original worksheet one started with

    First, code requires code tags. I'll address your question because you're a new user but please see the note at the end of my post.

    This description is a bit confusing, because you say, "This sheet is at random. ...Either way I don’t know how to get the macro to go back to the sheet I copied from." What I don't understand is how you can have code that copies from a location without knowing what that location is.

    Also, it is not necessary to unprotect to be able to copy from a sheet.

    Me.Sheets doesn't exist. Me represents the sheet containing the code, which may be what you're trying to do. Sheets is the collection of all sheets (both worksheets and chart sheets) in the workbook. Any attribute or method that you can access using Me, you can also omit the Me because it is implied.

    You don't have to do a separate copy and paste. If you really need a copy and paste, you can do it in one line for most cases. If you need a special paste, like transpose, then you will need two separate statements.

    For example, if you want to copy a range of cells in one sheet to another, and the code is in the "from" sheet, you could use this modified version of your code above:

    Please Login or Register  to view this content.
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Last edited by 6StringJazzer; 11-21-2012 at 04:45 PM. Reason: added rule
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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