+ Reply to Thread
Results 1 to 4 of 4

Replace tab as new one with same name is imported.

  1. #1
    Registered User
    Join Date
    10-01-2023
    Location
    Ohio
    MS-Off Ver
    Multiple - Windows and MAC
    Posts
    2

    Replace tab as new one with same name is imported.

    I have the below macro. It imports excel workbooks into my current workbook as an additional sheet. Is there a way for a duplicate sheet with the same name to overwrite and remove the original, rather than add the (2) or (3) after the name? For example, if Robert is already imported, I don't want Robert(2) if it's reimported. I'd like the new Robert to overwrite the original.

    In some cases, the sheets I'm importing will be updated through the day and the updated one will need to replace the original.


    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Replace tab as new one with same name is imported.

    You would need to check if ws.Name exists (routines available to do that) and, if it does, delete it before copying ws.

    Alternatively, assume the sheet does exist already and try to delete it. Use error handling to cater for the scenario where the sheet does not exist.

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    10-01-2023
    Location
    Ohio
    MS-Off Ver
    Multiple - Windows and MAC
    Posts
    2

    Re: Replace tab as new one with same name is imported.

    OK, where in my original macro should I insert this?

    I've tried different locations, but it's still importing as filename(2)

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Replace tab as new one with same name is imported.

    Try (untested):

    Please Login or Register  to view this content.

+ 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] SUMIFS function that can sum data imported as text without user changing the imported data
    By barnett2000 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-11-2022, 03:24 PM
  2. [SOLVED] Find and Replace Macro to replace list of special characters
    By dcowiesmith in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-22-2021, 02:01 PM
  3. Replies: 0
    Last Post: 02-13-2021, 03:32 AM
  4. Replies: 1
    Last Post: 02-27-2018, 11:22 AM
  5. add imported text file name above imported data
    By tompie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-27-2009, 08:18 AM
  6. [SOLVED] find and replace - replace data in rows to separated by commas
    By msdker in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-14-2006, 08:10 PM
  7. Replies: 3
    Last Post: 02-27-2006, 12: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