+ Reply to Thread
Results 1 to 6 of 6

Copying tabs in a workbook and buttons in new workbook still referencing the last workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    07-30-2021
    Location
    london
    MS-Off Ver
    365
    Posts
    3

    Copying tabs in a workbook and buttons in new workbook still referencing the last workbook

    Hi,

    I am fairly new to VBA. I have created a worksheet that has a number of macros. I am trying to copy this worksheet in the same workbook. When i copy the tab all new buttons in my worksheet reference the old sheet. This means i have to go to each button and assign them to a new macro name. i.e. Sheet2Hide_series needs to be assigned to sheet3Hide_series.

    Would anyone be able to help explain how i can copy worksheets and automatically update the links in my buttons rather than manually assigning all links?

    thanks in advance

  2. #2
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Copying tabs in a workbook and buttons in new workbook still referencing the last work

    And how are we supposed to know how it all works?
    See the yellow banner with instructions on how to place a sample file. (with your code)
    Messages have been translated from Dutch to English by means of google translate.

  3. #3
    Registered User
    Join Date
    07-30-2021
    Location
    london
    MS-Off Ver
    365
    Posts
    3

    Post Re: Copying tabs in a workbook and buttons in new workbook still referencing the last work

    I've attached an example of the issue. You will notice that when i copy and paste sheet 1 the buttons "add" and "delete" do not work.

    I can assign the button to the new sheet but in sheets that have lots of buttons it takes a long time. Any idea?
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    01-02-2020
    Location
    Idaho, USA
    MS-Off Ver
    365
    Posts
    274

    Re: Copying tabs in a workbook and buttons in new workbook still referencing the last work

    It will work if you put the code in a separate module. Here is an example file.
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Copying tabs in a workbook and buttons in new workbook still referencing the last work

    Defined names are not necessary. Do not use select and selection. Make the layout so that it does not bother you when copying. To insert a row:
    Sub VenA_add()
      x = Application.Match("Total", Columns(2), 0)
      Rows(x - 1).Copy
      Rows(x - 1).Insert
      Cells(x, 2).Resize(, 5) = Array("[Item]", "", 0, 0, "Update")
      Application.CutCopyMode = False
    End Sub
    To delete the active row:
    Sub VenA_delete()
      x = Application.Match("Total", Columns(2), 0)
      y = ActiveCell.Row
      If y > 3 And x > 5 And y < x Then
        Rows(y).Delete
       Else
        MsgBox "Unable to delete the item."
      End If
    End Sub
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    07-30-2021
    Location
    london
    MS-Off Ver
    365
    Posts
    3

    Re: Copying tabs in a workbook and buttons in new workbook still referencing the last work

    Thank you both!

+ 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. Referencing and copying from another open workbook
    By Darkcloud617 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-21-2020, 09:06 AM
  2. [SOLVED] Copying tabs (which mach the name of tabs in cuurent workbook) from another workbook
    By stevoDE in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-27-2017, 11:45 AM
  3. [SOLVED] Index Match Function Within One Workbook Referencing Cells in Another workbook error
    By Hackboss007 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-18-2014, 12:06 PM
  4. [SOLVED] Trouble copying data from closed workbook into active workbook, referencing help
    By lepperga in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-20-2013, 01:48 PM
  5. [SOLVED] Extract data from a workbook with multiple tabs, into a workbook with corresponding tabs
    By krackaberr in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-28-2013, 11:54 AM
  6. Replies: 2
    Last Post: 01-18-2010, 06:52 PM
  7. Replies: 1
    Last Post: 04-01-2006, 03:50 PM

Tags for this Thread

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