+ Reply to Thread
Results 1 to 4 of 4

Problem with add a sheet to workbook macro

  1. #1
    Registered User
    Join Date
    02-28-2008
    Posts
    36

    Problem with add a sheet to workbook macro

    I have a workbook where I have a button to add a sheet, this works fine except for a formula that the macro edits on every sheet so we can have a running total quantity for the project. The problems occurs if the user changes the name of the last sheet in the workbook, then adds a sheet then the formula gets a reference error. The sheets are named 1 , 2 ,3 and so on, but it is nice to be able to change tha name of the sheet to the date.

    Here is the code that Im have problems with

    Please Login or Register  to view this content.
    is there a code that would always reference the the previous sheet or I know that every sheet has 2 names a permanent sheet name that is Sheet1 Sheet2 and so on and the name that is shown on the tab at the bottom of the workbook, is there a way I can reference the permanent sheet name that would be a variable because I always need this formula to go to the previous page.

    Any help is appreciated.
    Thanks
    Last edited by westonkw; 08-24-2009 at 10:49 AM.

  2. #2
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: Problem with add a sheet to workbook macro

    I'm not quite sure what you mean by the previous sheet.

    This will grab the name of the sheet three sheets to the left of the active sheet.

    Please Login or Register  to view this content.

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Problem with add a sheet to workbook macro

    Hi westonkw,

    You can reference the sheets using their index number rather than their code name or tab name, like so:
    Please Login or Register  to view this content.
    This points to the sheet that is 1 sheet to the left of the activesheet. Change "ws.Index - 1" to "ws.Index - 3" or whatever you need.

  4. #4
    Registered User
    Join Date
    02-28-2008
    Posts
    36

    Re: Problem with add a sheet to workbook macro

    Thanks Paul, Worked Great!!

+ 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