+ Reply to Thread
Results 1 to 6 of 6

Problem with duplicates when auto naming sheets

Hybrid View

fyrsten Problem with duplicates when... 03-16-2015, 04:53 PM
NeedForExcel Re: Problem with duplicates... 03-17-2015, 12:22 AM
fyrsten Re: Problem with duplicates... 03-17-2015, 03:01 AM
NeedForExcel Re: Problem with duplicates... 03-17-2015, 03:14 AM
fyrsten Re: Problem with duplicates... 03-17-2015, 03:46 AM
NeedForExcel Re: Problem with duplicates... 03-17-2015, 04:43 AM
  1. #1
    Registered User
    Join Date
    03-16-2015
    Location
    Denmark
    MS-Off Ver
    Office 360
    Posts
    8

    Problem with duplicates when auto naming sheets

    Hey

    I have this problem with duplicates when i use a macro to auto name the sheets in the workbook. I have these cell references:

    Every time i change E5 it won't change all of the sheetnames, ant this is because of the rule about no sheets can have the same name.

    Sheet 1
    E5 F5 G5 H5 I5
    2000 : =E5+1 : =F5+1 : =G5+1 : =H5+1

    Then Sheet 2 (B2=sheet1E5)
    And sheet 3 (B2=sheet1F5)
    And so on.

    Then i use this macro to auto name the sheets (Under modules):
    Sub NameWS()
    On Error Resume Next
    For Each ws In ThisWorkbook.Worksheets
    ws.Name = Left(ws.Cells(2, 2).Value, 31)
    Next
    On Error GoTo 0
    End Sub

    And then this macro under each sheet:
    Private Sub Worksheet_Change(ByVal Target As Range)
    NameWS
    End Sub

    This is the example: http://s000.tinyupload.com/index.php...79914936788269

    Is there a way how to make the sheetnames turn at the same time?

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Problem with duplicates when auto naming sheets

    The Sheet names are indeed changing automatically at my end..
    Cheers!
    Deep Dave

  3. #3
    Registered User
    Join Date
    03-16-2015
    Location
    Denmark
    MS-Off Ver
    Office 360
    Posts
    8

    Re: Problem with duplicates when auto naming sheets

    Yes, but if you change E5 from 2000 to 2001, then only sheet5 will change to 2005 right? And if you change E5 to 2006 instead, then they will all change, right?

  4. #4
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Problem with duplicates when auto naming sheets

    Here!

    Try This

    Sub NamesWS()
    
        Application.ScreenUpdating = False
        
        Dim SheetCount As Integer, Counter As Integer, WSName As String, NewName As String
        
        SheetCount = ThisWorkbook.Worksheets.Count
        
        For Counter = 1 To SheetCount
        
            Worksheets(Counter).Activate
            WSName = Worksheets(Counter).Name
            
            If WSName <> "Start" Then
                NewName = Cells(2, 2).Value
                ActiveSheet.Name = NewName & "X"
            End If
        
        Next Counter
        
        For Counter = 1 To SheetCount
        
            Worksheets(Counter).Activate
            WSName = Worksheets(Counter).Name
            
            If WSName <> "Start" Then
            
                WSName = Application.WorksheetFunction.Substitute(WSName, "X", "")
                ActiveSheet.Name = WSName
            End If
        
        Next Counter
        
        Worksheets("Start").Activate
        
        Range("E5").Activate
        
        Application.ScreenUpdating = True
    
    End Sub
    And Dont Forget This -

    Private Sub Worksheet_Change(ByVal Target As Range)
        NamesWS
    End Sub

  5. #5
    Registered User
    Join Date
    03-16-2015
    Location
    Denmark
    MS-Off Ver
    Office 360
    Posts
    8

    Re: Problem with duplicates when auto naming sheets

    That worked perfectly.. Thanks!

  6. #6
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Problem with duplicates when auto naming sheets

    Glad It Worked!

+ 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. Need help with copying rows, replicating sheets, naming sheets and assigning print area...
    By Navin Agrawal in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-05-2014, 09:21 AM
  2. Auto-populate from other sheets in a master, than auto total duplicates
    By Melyd in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-30-2013, 01:48 PM
  3. Memory problem from macro creating and naming sheets from Array?
    By acj06 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-27-2011, 02:23 PM
  4. problem with creating and naming sheets
    By dschmitt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-16-2010, 01:19 AM
  5. Re-Naming Sheets per Cell data & Hiding Sheets
    By dej222 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-26-2009, 10:20 PM

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