+ Reply to Thread
Results 1 to 3 of 3

Dynamically inserting a worksheet using After:=

  1. #1
    Registered User
    Join Date
    07-17-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    13

    Dynamically inserting a worksheet using After:=

    Hi guys,

    I'm having trouble getting a worksheet to copy after the sheet I want.

    Please Login or Register  to view this content.
    I have a number of worksheets (currently numbered 1 to 10) as well as some others called various different things - the important thing is that the worksheet named 1 is not the first sheet in the workbook (and I don't want to hard code it as it may change).

    My problem is that when I create a worksheet called 4, it is being inserted after the 3rd worksheet, not the worksheet called 3.

    Hope that makes a bit of sense!!

    I think it's this line that is the problem:
    Please Login or Register  to view this content.
    Ideally I would like to use the codename property but I can't seem to make that work.

    Thanks in advance
    Sandra
    Last edited by Loonytoons; 12-23-2014 at 11:20 AM.

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

    Re: Dynamically inserting a worksheet using After:=

    Sandra

    Are you using numbers, eg 1,2,3 etc, to name the sheets?

    If you are that could be causing a conflict btween sheet index and sheet name.

    For example in code if you had Sheets(3) it would refer to the sheet with index 3, not necessarily the sheet with the name '3'.

    To ensure you are referring to the sheet with the name 3 use CStr.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    07-17-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    13

    Re: Dynamically inserting a worksheet using After:=

    Thanks Norie - that was it!

+ 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. Copying cells dynamically to a worksheet based on values in another worksheet
    By freelance in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-10-2013, 01:45 PM
  2. Dynamically add Worksheet / rename / update the formula to include the new worksheet
    By Rajnishbhatt in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-30-2012, 12:31 AM
  3. Dynamically add code to a worksheet
    By elliebee in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-14-2010, 12:29 PM
  4. How to add a worksheet dynamically
    By maverick3483 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-13-2009, 11:38 PM
  5. [SOLVED] dynamically referencing to another worksheet
    By D23 in forum Excel General
    Replies: 2
    Last Post: 06-23-2006, 11:10 AM

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