+ Reply to Thread
Results 1 to 6 of 6

Macro for renaming sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    10-03-2007
    Posts
    21

    Macro for renaming sheets

    Thank you all for your help in the past. My skill level is pretty low so I greatly appreciate it.
    Here’s my situation that I need help on:
    I have a sheet with 200 names on it organized into columns by last name, first name, category, etc. I need to provide a sheet for each name. Basically, a workbook with 200 sheets and the name of each sheet is equal to the last name.
    Is there a macro that I can run that
    (1) will first “take row 2 of Sheet1 and paste it to row 2 of sheet 2”
    (2) then “it will change the name of ‘Sheet2’ to equal the person’s last name located in ‘A2’ of the same sheet (Sheet2)”
    (3) and finally it will “repeat the process on Sheet3; copying row 3 of Sheet1 to row 2 of Sheet3 and then renaming Sheet3 to equal the person’s last name located in ‘A2’ of the same sheet (Sheet3).
    It obviously does not have to be performed by only one macro. Any advice would be greatly appreciated.
    -Joe

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Maybe

    Sub Macro1()
    Dim Lr As Long
    Dim NWsht As Worksheet
    Dim SrcSht As Worksheet
    Set SrcSht = Sheets("Sheet1") ' Change to your name
    Lr = Cells(Rows.Count, "A").End(xlUp).Row
    Application.ScreenUpdating = False
        For i = 2 To Lr
            Set NWsht = Sheets.Add
            NWsht.Move After:=Sheets(Sheets.Count)
        
            NWsht.Rows(2).Value = SrcSht.Rows(i).Value
            NWsht.Name = NWsht.Range("A2").Value
        Next i
    Application.ScreenUpdating = True
    End Sub
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Some error checking

    Sub Macro1()
    Dim Lr As Long, M As Long
    Dim NWsht As Worksheet
    Dim SrcSht As Worksheet
    Set SrcSht = Sheets("Sheet1") ' Change to your name
    Lr = Cells(Rows.Count, "A").End(xlUp).Row
    Application.ScreenUpdating = False
    On Error Resume Next
        For i = 2 To Lr
            Set NWsht = Sheets.Add
            NWsht.Move After:=Sheets(Sheets.Count)
            
            NWsht.Rows(2).Value = SrcSht.Rows(i).Value
                 NWsht.Name = NWsht.Range("A2").Value
             If Err.Number <> 0 Then
                MsgBox Err.Number & " " & Err.Description
                Err.Clear
                M = MsgBox("Stop Macro!!", vbYesNo)
                If M = vbYes Then
                    Exit For
                End If
             End If
           
        Next i
    Application.ScreenUpdating = True
    End Sub
    VBA Noob

  4. #4
    Registered User
    Join Date
    10-03-2007
    Posts
    21
    Absolutely Amazing! Thank you so much. You don’t understand how much time and aggravation you just saved me…actually, you probably do.

    One more question; On the line :
    Set SrcSht = Sheets("Sheet1")
    ' Change to your name, am I supposed to change the text to my name? if so, what is the function of that?

    Thank you again your expertise,
    Joe
    Last edited by VBA Noob; 02-10-2008 at 05:31 PM.

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Set SrcSht = Sheets("Sheet1")
    is Sourcesheet for the names

    VBA Noob

  6. #6
    Registered User
    Join Date
    10-03-2007
    Posts
    21
    Got it.

    Thank you again VBA Noob. I truly appreciate it!

    -Joe

+ 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