+ Reply to Thread
Results 1 to 3 of 3

Sheet Name Macro Problems

  1. #1
    Registered User
    Join Date
    03-22-2005
    Posts
    31

    Sheet Name Macro Problems

    Hey everyone, I'm working on a sheet where it has all the months down the bottom, and a summary tab. I want the worksheet so when I click a button for the next year, it automatically changes it from "July 05" to "July 06" for each one. I did a pretty dodgy recorded macro and it worked initially, but for the next year It came up with an error because it still looks for sheet "July 05" instead of sheet "July 06". Is there any way to fix this or a better technique for doing this?? thanks guys, btw, ive attached an original copy of the DB and one with the macro. Thanks again
    Attached Files Attached Files
    Last edited by carlito_1985; 04-26-2005 at 10:54 PM.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Carlito

    Try this on a back up copy of your work book

    I have re written your code - You will need to replace your code with mine


    I have coded it when re nameing sheets to add 1 to the last 2 digits of the existing sheet name (Does not change summary sheet) and enter the same formula to each sheet



    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 27/04/2005 by AGizariotis
    ' Modified by Mudraker 27/4/2005

    '
    Dim Ws As Worksheet
    Dim sName As String
    Dim sFormula As String

    iYear = Format(Year(Now()) + 1, "yy")
    For Each Ws In Worksheets
    If Ws.Name <> "SUMMARY" Then
    sName$ = Left(Ws.Name, Len(wsname) - 2)
    Ws.Name = sName & Format(Right(Ws.Name, 1) + 1, "yy")
    Ws.Columns("T:T").NumberFormat = "@"
    Ws.Range("T7").FormulaR1C1 = "=RIGHT(T5,2)"
    Ws.Range("S7").FormulaR1C1 = "=RIGHT(R[-2]C[1],2)"
    Ws.Range("S9").FormulaR1C1 = "=R[-2]C+1"
    Ws.Range("S10").FormulaR1C1 = "=""0""&R[-1]C"
    sFormula$ = "=" & sName & " &R[-1]C"
    Ws.Range("S11").FormulaR1C1 = sFormula
    Ws.Range("P3:U17").ClearContents
    End If
    Next Ws
    Sheets("SUMMARY").Select
    Range("A1:G1").Select
    End Sub

  3. #3
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Carlito

    I left a . out of the code
    sName$ = Left(Ws.Name, Len(wsname) - 2)
    should have been
    sName$ = Left(Ws.Name, Len(wWs.Name) - 2)

    I also spotted an error in this line
    Ws.Name = sName & Format(Right(Ws.Name, 1) + 1, "yy")
    should be
    Ws.Name = sName & Format(Right(Ws.Name, 2) + 1, "00")

    This line is also no longer required
    iYear = Format(Year(Now()) + 1, "yy")


    Try this version of the macro

    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 27/04/2005 by AGizariotis
    ' Modified by Mudraker 27/4/2005

    '
    Dim Ws As Worksheet
    Dim sName As String
    Dim sFormula As String

    For Each Ws In Worksheets
    If Ws.Name <> "SUMMARY" Then
    sName$ = Left(Ws.Name, Len(Ws.Name) - 2)
    Ws.Name = sName & Format(Right(Ws.Name, 2) + 1, "00")
    Ws.Columns("T:T").NumberFormat = "@"
    Ws.Range("T7").FormulaR1C1 = "=RIGHT(T5,2)"
    Ws.Range("S7").FormulaR1C1 = "=RIGHT(R[-2]C[1],2)"
    Ws.Range("S9").FormulaR1C1 = "=R[-2]C+1"
    Ws.Range("S10").FormulaR1C1 = "=""0""&R[-1]C"
    sFormula$ = "=" & sName & " &R[-1]C"
    Ws.Range("S11").FormulaR1C1 = sFormula
    Ws.Range("P3:U17").ClearContents
    End If
    Next Ws
    Sheets("SUMMARY").Select
    Range("A1:G1").Select
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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