+ Reply to Thread
Results 1 to 3 of 3

Vba to open closed tabs in a work book then close them

Hybrid View

  1. #1
    Registered User
    Join Date
    02-10-2018
    Location
    toronto ontario
    MS-Off Ver
    office 2010
    Posts
    66

    Vba to open closed tabs in a work book then close them

    Hi all
    I have a bit of a problem with some code I wrote if the tabs sheets are open then the copy move function works fine What I need is to open then close the tabs sheets as it runs
    Hope some one can help me

    Sub Move()
    '
    ' Move all Entries for the next year
    
    
    myCheck = MsgBox("Warning Warning. " & vbCrLf & "This will Move all Data To Past Member and Reset the Master Mem Tab . " & vbCrLf & _
            "Do you wish to continue?", vbYesNo + vbInformation, "Message Box")
        
        If myCheck = vbNo Then Exit Sub
    
    Dim TabName As String
        
        Sheets("Six Year Derby").Select
          Range("B5:S46").Select
          Selection.ClearContents
        
        Sheets("Five Year Derby").Select
          Range("B5:S46").Select
          Selection.Copy
          Sheets("Six Year Derby").Select
        ActiveSheet.Paste
        
        Sheets("Four Year Derby").Select
           Range("B5:S46").Select
           Selection.Copy
           Sheets("Five Year Derby").Select
         ActiveSheet.Paste
        
        Sheets("Three Year Old").Select
           Range("B5:S46").Select
           Selection.Copy
           Sheets("Four Year Derby").Select
         ActiveSheet.Paste
        
        Sheets("Two Year Old").Select
           Range("B5:S46").Select
           Selection.Copy
           Sheets("Three Year Old").Select
         ActiveSheet.Paste
          
        Sheets("Yearling Year").Select
           Range("B5:S46").Select
           Selection.Copy
           Sheets("Two Year Old").Select
        ActiveSheet.Paste
        
        Sheets("Weanling Year").Select
           Range("B5:S46").Select
           Selection.Copy
           Sheets("Yearling Year").Select
        ActiveSheet.Paste
    
    Sheets("Weanling Year").Select
           Range("A5:S46").Select
          Selection.ClearContents
         ActiveCell.Select
            
            Sheets("Weanling Year").Select
         Application.CutCopyMode = False
    End Sub
    Last edited by mmikem; 01-02-2019 at 08:56 PM.

  2. #2
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Vba to open closed tabs in a work book then close them

    Your description is a bit confusing, when you say open and close tabs sheet, are you referring to hidden sheets, or closed files?

    Your code only refers to sheets within a single file, yet your description suggests otherwise.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Vba to open closed tabs in a work book then close them

    Hi,

    You don;t need to select stuff just in order to copy it and paste it somewhere else. In fact .Selectin and .Activate are raely necessary. This means you can work with hidden sheets.

    So for instance where you have
          Sheets("Six Year Derby").Select
          Range("B5:S46").Select
          Selection.ClearContents
    use instead

    Sheets("Six Year Derby").Range("B5:S46").ClearContents
    And another improvment, don't use sheet tab names, they are too easily changed by a user and will cause your code to fail. Use the VBA Sheet Code name instead.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Copy sheet from closed wkbk to any open book, using VBA that's in personal.xls
    By franklin_m in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-22-2017, 01:23 PM
  2. Open Closed Book, carry out a VLookup and then put all entries into blank book
    By AChatwin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-22-2015, 03:17 AM
  3. [SOLVED] SUMPRODUCT multiple criteria in closed work book
    By DannyJ in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-12-2015, 05:26 PM
  4. Replies: 2
    Last Post: 05-08-2015, 11:21 PM
  5. Data copy Automatically into closed work book
    By rajeev.raj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-18-2013, 12:25 AM
  6. Replies: 0
    Last Post: 11-13-2011, 06:57 AM
  7. Open book, check for macros, close book
    By CLR in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-31-2005, 02:06 PM

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