+ Reply to Thread
Results 1 to 8 of 8

Subscript out of range in VBA copying a template

  1. #1
    Registered User
    Join Date
    05-25-2017
    Location
    Virginia
    MS-Off Ver
    2016
    Posts
    5

    Question Subscript out of range in VBA copying a template

    Hello. I come here seeking help, I have tried searching for a solution for this but i still don't know what's wrong.

    I have this error: Run-time error '9': Subscript out of range.

    In debug it opens my VBA:

    Application.ScreenUpdating = False 'Hide screen flashing while creating and sorting
    Sheets("Template").Visible = True 'Make sheet visible before Copy
    > Sheets("Template").Copy After:=Sheets(3) 'copy template
    ActiveSheet.Name = NewNameToAdd 'rename new sheet
    Sheets("Template").Visible = False 'Hide Template

    The stop line is Sheets("Template").Copy After:=Sheets(3)

    I have never had a problem with this before, and no matter how I run it, I get the same error.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Subscript out of range in VBA copying a template

    How many worksheets does the workbook the sheet 'Template' is in have?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    05-25-2017
    Location
    Virginia
    MS-Off Ver
    2016
    Posts
    5

    Re: Subscript out of range in VBA copying a template

    18 currently

  4. #4
    Registered User
    Join Date
    05-25-2017
    Location
    Virginia
    MS-Off Ver
    2016
    Posts
    5

    Re: Subscript out of range in VBA copying a template

    Also.... it appears for some reson, It's not there. I'm going to fix that.

  5. #5
    Registered User
    Join Date
    05-25-2017
    Location
    Virginia
    MS-Off Ver
    2016
    Posts
    5

    Re: Subscript out of range in VBA copying a template

    That was the weirdest thing ever. How does a hidden sheet just disappear?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Subscript out of range in VBA copying a template

    Is there definitely a sheet with the exact name 'Template' in the active workbook when you run the code?

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Subscript out of range in VBA copying a template

    Could it have been renamed rather than disappeared?

  8. #8
    Registered User
    Join Date
    05-25-2017
    Location
    Virginia
    MS-Off Ver
    2016
    Posts
    5
    Quote Originally Posted by Norie View Post
    Could it have been renamed rather than disappeared?
    The VBA has been run many times before, I can see no way it could have done that. I unhide the the template, make a copy, hide the template. And the template is only accessed if I'm editing functions.

+ 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. Replies: 1
    Last Post: 06-15-2015, 01:56 AM
  2. VBA template population - Subscript Error
    By kenadams378 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-24-2014, 04:44 PM
  3. [SOLVED] Subscript out of Range when copying multiple worksheet selections
    By apbourdet in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-10-2014, 09:13 PM
  4. copying template sheet containing chart with dynamic range
    By mc36155 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-12-2013, 04:16 AM
  5. Subscript out of range error while populating array from range.
    By Aussiexile in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-04-2010, 02:22 AM
  6. Subscript out of range error when trying to select a range
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2010, 07:57 PM
  7. Copying Sheet - subscript out of range error
    By GSP@DCS in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-01-2006, 09:00 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