+ Reply to Thread
Results 1 to 12 of 12

VBA Worksheet Tab Rename Macro Causing Excel Infinite Loop

Hybrid View

  1. #1
    Registered User
    Join Date
    04-14-2011
    Location
    Bay Area, CA
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: VBA Worksheet Tab Rename Macro Causing Excel Infinite Loop

    I checked & do not have legacy code laying around. Is the reason I'm getting an error because of the "On Error Resume Next" or "On Error Goto 0" (admittedly, I don't really know what these 2 statements do).

    And since each sheet will be a quote we receive from a supplier, there will never be a time where there is more than 1 sheet w/ the same supplier, because the whole reason for copying the sheet is if we have more than 1 supplier who has supplied us w/ quotes - thus, each sheet would be the quote from a unique supplier, hence a unique tab name.

    As far as how the events should occur: The user opens the sheet & fills out the stuff in yellow. When the user selects the supplier via the drop-down, the tab should rename. If there is more than 1 supplier, then the user should right-click on the tab & make a copy of that sheet, and then start filling it out w/ the unique information, including selecting a different supplier, which, in turn, will rename that sheet accordingly.

    Right now, when I right-click & select "copy", it does create a 2nd sheet w/ the same name as the 1st sheet, but w/ the (2) added to it - which I'm ok with, as long as the user can overwrite that new name by selecting a different supplier from the drop-down.... The issue is that it pops up the "Cannot rename a sheet to the same name as another sheet" error, to which there are 3 options: End, Debug, and Help.

    If I click "End" then the error goes away, but I guess it kicks itself OUT of the macro, because when I choose a different supplier for the 2nd sheet, the sheet does not rename (and for that matter, Cell B22 doesn't update either). I can select a new supplier from the drop-down, but the rest of the updates do NOT occur.

    Is this something you can replicate on your end?

    And I guess I just want it to NOT pop-up the "Error" message, and to allow the updates / refreshes to occur on the new sheet.

    Thank you!
    Last edited by rbrookov; 05-07-2014 at 07:08 PM. Reason: changed from cell C10 to B22

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: VBA Worksheet Tab Rename Macro Causing Excel Infinite Loop

    Start out with fresh with just the one worksheet and just this code for the Combobox1_Change.

    Private Sub ComboBox1_Change()
        
        Dim strNewName As String
        
        If ComboBox1.ListIndex > -1 Then    'Test if anything is selected from the list
        
            Range("B22").Value = ComboBox1.Text
            
            strNewName = ComboBox1.Text & Format(Range("I1").Value, "_yy")  'New name
            
            If Not Evaluate("ISREF('" & strNewName & "'!A1)") Then  'Test if worksheet name already exists
                
                Me.Name = strNewName    'Rename sheet
                
                'Prompt to copy invoice
                If MsgBox("Do you want to enter another Quote? ", vbQuestion + vbYesNo, _
                          "Another Vendor") = vbYes Then Me.Copy After:=Me
                          
            Else
                MsgBox strNewName, vbExclamation, "Vendor Quote Already Exists"
            End If
            
        End If
        
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ 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. BeforeRightClick causing infinite loop and slow calculation
    By k64 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-28-2013, 07:18 PM
  2. Excel 2007 - Print Macro - Infinite Loop Issue
    By Fraenk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-03-2012, 07:50 AM
  3. worksheet rename using location causing error
    By wejones in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-06-2011, 08:46 PM
  4. Macro goes into an infinite loop
    By excelforum123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-21-2010, 10:08 AM
  5. [SOLVED] worksheet change infinite loop/calculate for user functions
    By Mike in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2006, 12:30 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