+ Reply to Thread
Results 1 to 5 of 5

Macro for copy and number new sheet

  1. #1
    Registered User
    Join Date
    04-28-2013
    Location
    Magyarország
    MS-Off Ver
    2010
    Posts
    9

    Macro for copy and number new sheet

    Hi everybody!

    I am new at VBA, and I have some problem. I would like to make a code for copy a template sheet called V000 and name as V001. If V001 exsist call it V002... etc.

    I already have found some formula but it's not working stg is missing and I don't know what:
    Thanks for ur help!
    Sub NewVendor()
    'Copy template V000 and rename it
    Dim V0 As Worksheet
    Sheets("V000").Select
    ActiveSheet.Copy After:=Sheets(Sheets.Count - 2)
    Set V0 = ActiveSheet


    Const strPrefix = "V0"
    Const strFormat = "00"
    Dim wsh As Worksheet
    Dim lngMax As Long
    Dim lngNum As Long
    For Each wsh In Worksheets
    If wsh.Name Like strPrefix & "*" Then
    lngNum = Val(Mid(wsh.Name, Len(strPrefix) + 1))
    If lngNum > lngMax Then
    lngMax = lngNum
    End If
    End If
    Next wsh
    Set wsh = Worksheets.Add(After:=Worksheets(Worksheets.Count))
    wsh.Name = strPrefix & Format(lngMax + 1, strFormat)
    End Sub

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro for copy and number new sheet

    That code seems to work for me although it creates two worksheets, one called "V000 (2)". I don't think you need the lines at the top with V0, just:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-28-2013
    Location
    Magyarország
    MS-Off Ver
    2010
    Posts
    9

    Re: Macro for copy and number new sheet

    So now the sheet name is okey, but my problem that I need to copy a template sheet which called V000 and AFTER THAT rename it because I already have several data on it.

    Quote Originally Posted by yudlugar View Post
    That code seems to work for me although it creates two worksheets, one called "V000 (2)". I don't think you need the lines at the top with V0, just:
    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro for copy and number new sheet

    In that case:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-28-2013
    Location
    Magyarország
    MS-Off Ver
    2010
    Posts
    9

    Re: Macro for copy and number new sheet

    Thank's working perfect!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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