+ Reply to Thread
Results 1 to 7 of 7

Need VBA formula that will link to same worksheet even if sheet name changes

  1. #1
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Need VBA formula that will link to same worksheet even if sheet name changes

    NOTE TO MODERATORS: I KNOW the Code element below is not in echelons. if I put them in. your SUCURI Firewall blocks the post! If someone can explain how to get round this I would be extremely grateful.

    Going round in circles here, so hope someone can help.

    User enters the number of worksheets to be created.
    Macro creates that number of sheets, and names each one as "(whatever) & i" (where i is the current number created).
    Macro then adds a column to the SUMMARY sheet for each new sheet created.
    Works perfectly

    Challenge: Each worksheet will be filled in, creating a series of subtotals.
    I need VBA to produce "formulae" on the SUMMARY sheet that link to the relevant worksheet and cell range automatically, even if the User change the sheet name at some point

    I tried setting each new sheet as "ws3" when it was created and used that in the "formulae" (e.g


    Range("C6").Select
    ActiveCell = "=" & sh3.Name & "!F6:F9"

    But every time the Code adds a new sheet, sh3 becomes the new "Active" sheet, which changed the formulae on all the previous columns.

    Any suggestions. pointers or alternatives welcome as ever.

    Ochimus
    Last edited by Ochimus; 09-18-2018 at 02:17 PM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Need VBA formula that will link to same worksheet even if sheet name changes

    You could try using the code name for the sheet e.g. Sheet1. This is the value that appears in the top left hand pane of the VBA editor.
    Martin

  3. #3
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Need VBA formula that will link to same worksheet even if sheet name changes

    .
    Try Sheet1 ... Sheet2 ... Sheet3 etc.

    In the VBE you see Sheet3(Sheet3) ... or you may see Sheet3(sh3) if the tab has been named sh3.
    In VBA it would be referred to as Sheets("Sheet3") ... or Sheets("sh3") if the tab was renamed.

    Using Sheet3 refers to the left side of the sheet name ... Sheet3(Sheet3) ... which doesn't change.

    Hope that helps ?

  4. #4
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Need VBA formula that will link to same worksheet even if sheet name changes

    Many thanks to both for the prompt responses, but need some clarification?

    How do I write the Code to "see" the new sheet number as it's created?

    It is almost certainly not going to be sequential, as the "real" file jumps from sheet9 to sheet62 already!

    Ochimus

  5. #5
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Need VBA formula that will link to same worksheet even if sheet name changes

    .
    Best to post your workbook with the code. Do not include any confidential information.

  6. #6
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Need VBA formula that will link to same worksheet even if sheet name changes

    No idea what happened the first time I ran the Code, but I retried the "make the active sheet sh3" approach yesterday, and it didn't "reset" the formulae in the previous columns of the Summary sheet.

    So I can mark this as "solved", but grateful for the prompt responses from both of you.

    Ochimus

  7. #7
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Need VBA formula that will link to same worksheet even if sheet name changes

    .
    Glad you have it solved.

+ 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] Get the data from sheet 1 link to sheet 2 using formula
    By ALLANT in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-07-2016, 11:20 PM
  2. Replies: 0
    Last Post: 02-18-2016, 07:26 AM
  3. Formula to link cell on one sheet to changing cells on another sheet
    By Patish in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-18-2014, 12:55 PM
  4. Want to permanently Link cells on a new Worksheet to main sheet.
    By Fiddler in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-17-2014, 04:23 AM
  5. [SOLVED] How to put a formula in a link to another worksheet
    By ssiegel in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-10-2013, 12:45 PM
  6. macro that will automatically link a newly created worksheet to a summary sheet
    By liquidblack in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2009, 03:22 PM
  7. Copying a Formula which contains a link to another worksheet
    By Shirley Munro in forum Excel General
    Replies: 4
    Last Post: 02-03-2006, 05:06 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