+ Reply to Thread
Results 1 to 3 of 3

VBA Basic Question: How to rename sheets within code so sheet renaming doesn't cause error

  1. #1
    Registered User
    Join Date
    08-15-2014
    Location
    Los Angeles, CA
    MS-Off Ver
    2010
    Posts
    2

    VBA Basic Question: How to rename sheets within code so sheet renaming doesn't cause error

    Hi,
    I understand this question has been addressed in general and for specific questions; however, with the advice, I'm still unable to change all of the code for the following scenario/macro so that when a user renames a sheet, it doesn't affect the code (err out). I was able to follow the previous advice in order change the first sheet referenced to the hardcoded name (sheet3 in the below which was once something else), but i'm unsure how to change sheet1! in the example below to its hardcoded name which is sheet6. Could you please help?

    Sub AdvancedFilter()
    '
    ' AdvancedFilter Macro
    '

    '
    Range("E1").Select
    Sheet3.Rows("4:1048576").AdvancedFilter Action:= _
    xlFilterCopy, CriteriaRange:=Range("Sheet1!Criteria"), CopyToRange:=Range( _
    "A21:LG21"), Unique:=False
    Range("A18").Select

    End Sub
    Last edited by jbl12345; 02-03-2015 at 03:36 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: VBA Basic Question: How to rename sheets within code so sheet renaming doesn't cause e

    Try

    Please Login or Register  to view this content.
    Martin

  3. #3
    Registered User
    Join Date
    08-15-2014
    Location
    Los Angeles, CA
    MS-Off Ver
    2010
    Posts
    2

    Re: VBA Basic Question: How to rename sheets within code so sheet renaming doesn't cause e

    Thank you very much. I subbed in sheet6 rather than sheet one and it worked:

    Range("E1").Select
    Sheet3.Rows("4:1048576").AdvancedFilter Action:= _
    xlFilterCopy, CriteriaRange:=Sheet6.Range("Criteria"), CopyToRange:=Range( _
    "A21:LG21"), Unique:=False
    Range("A18").Select



    Many Thanks

+ 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. Cannot rename a sheet to same name error - Need code to override error
    By o4008 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-13-2013, 12:43 PM
  2. [SOLVED] Code to create new sheet and rename, regardless of any other sheets in workbook
    By csh8428 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-19-2012, 02:22 PM
  3. Rename Sheet Tab Code Doesn't Handle Duplicates
    By irose_57 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-28-2011, 01:49 AM
  4. Code to delete sheets and rename sheets in a protected workbook?
    By leaning in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-07-2011, 03:02 AM
  5. excel sheet with visual basic doesn't open
    By uri rozen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-16-2006, 06:10 AM

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