+ Reply to Thread
Results 1 to 15 of 15

Worksheet Macro

Hybrid View

mahen2 Worksheet Macro 04-12-2013, 05:05 PM
AB33 Re: Worksheet Macro 04-12-2013, 05:12 PM
TMS Re: Worksheet Macro 04-12-2013, 05:19 PM
TMS Re: Worksheet Macro 04-12-2013, 05:20 PM
AB33 Re: Worksheet Macro 04-12-2013, 05:23 PM
mahen2 Re: Create Sheet Names(tab) 04-12-2013, 05:26 PM
TMS Re: Worksheet Macro 04-12-2013, 05:32 PM
AB33 Re: Worksheet Macro 04-12-2013, 05:37 PM
mahen2 Re: Worksheet Macro 04-12-2013, 05:43 PM
mahen2 Re: Worksheet Macro 04-12-2013, 05:50 PM
AB33 Re: Worksheet Macro 04-12-2013, 06:02 PM
TMS Re: Worksheet Macro 04-12-2013, 06:04 PM
mahen2 Re: Worksheet Macro 04-12-2013, 06:33 PM
TMS Re: Worksheet Macro 04-12-2013, 07:21 PM
TMS Re: Worksheet Macro 04-13-2013, 07:53 PM
  1. #1
    Registered User
    Join Date
    04-12-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    9

    Worksheet Macro

    I have two columns in sheet1. One is sheet Names and in column two Id numbers. I need to create worksheet with those names and enter appropriate Id number on to a cell (eg, in cell C3)

    Sheet Names Id Numbers
    Name1 A001
    Name3 R012
    Name7 A009
    ........ ........

    i need macro to perform this please.

    thanks

    Mahen

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Worksheet Macro

    Mahen,
    Welcome to the forum!
    Please change the name of your title which resembles your request.
    Something like: Create sheet names(tabs) based on column A, or names.
    It would make life easier if you could attach sample book with out any confidential information. To attach a sample, click advance then attachment

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,515

    Re: Worksheet Macro

    
    Sub TMS()
    Dim lLR As Long
    Dim cell As Range
    Dim sh As Worksheet
    With Sheets("Sheet1")
        lLR = .Range("A" & .Rows.Count).End(xlUp).Row
        For Each cell In .Range(.Cells(2, 1), .Cells(lLR, 1))
            Set sh = Sheets.Add(after:=Sheets(Sheets.Count))
            sh.Name = cell.Value
            sh.Range("A1") = cell.Offset(0, 1).Value
        Next 'cell
    End With
    End Sub

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,515

    Re: Worksheet Macro

    @AB33: apologies for responding whilst you have a rule compliance request in progress

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Worksheet Macro

    Trevor,
    You always are polite!

  6. #6
    Registered User
    Join Date
    04-12-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Create Sheet Names(tab)

    See attached file. Click on sheets and check in Cell C3. I have about fifty Names and Ids in sheet1

    Thanks
    Mahen
    Attached Files Attached Files

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,515

    Re: Worksheet Macro

    Option Explicit
    
    Sub TMS2()
    Dim lLR As Long
    Dim cell As Range
    Dim sh As Worksheet
    With Sheets("Sheet1")
        lLR = .Range("B" & .Rows.Count).End(xlUp).Row
        For Each cell In .Range(.Cells(3, 2), .Cells(lLR, 2))
            Set sh = Sheets.Add(after:=Sheets(Sheets.Count))
            On Error Resume Next
            sh.Name = cell.Value
            On Error GoTo 0
            sh.Range("C3") = cell.Offset(0, 1).Value
        Next 'cell
    End With
    End Sub

    Regards, TMS

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Worksheet Macro

    As an option
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    04-12-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Worksheet Macro

    TMShucks,
    Thank you. Working fine. Is it possible to Create a copy of a sheet and rename with the names in Sheet1?

    Mahen

  10. #10
    Registered User
    Join Date
    04-12-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Worksheet Macro

    AB33,
    Not quite right. Worksheet names has to be Name1, Name3....etc. Id numbers are placing correctly.

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Worksheet Macro

    Sorry! You are right!
    Corrected
    Attached Files Attached Files

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,515

    Re: Worksheet Macro

    Of course. Something like:


    Option Explicit
    
    Sub TMS3()
    Dim lLR As Long
    Dim cell As Range
    Dim sh As Worksheet
    With Sheets("Sheet1")
        lLR = .Range("B" & .Rows.Count).End(xlUp).Row
        For Each cell In .Range(.Cells(3, 2), .Cells(lLR, 2))
            Sheets("Template").Copy After:=Worksheets(Sheets.Count)
            Set sh = ActiveSheet
            On Error Resume Next
            sh.Name = cell.Value
            On Error GoTo 0
            sh.Range("C3") = cell.Offset(0, 1).Value
        Next 'cell
    End With
    End Sub

    Regards, TMS
    Last edited by TMS; 04-12-2013 at 07:19 PM.

  13. #13
    Registered User
    Join Date
    04-12-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Worksheet Macro

    TMS
    " missing after Template. Apart from that working pefectly.

    Thank you so much.

    regards,
    Mahen

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,515

    Re: Worksheet Macro

    Ah, sorry about that. It wasn't what I used to test

    Glad you could sort it.

    Regards, TMS



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  15. #15
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,515

    Re: Worksheet Macro

    Please mark your thread solved (as above). Thanks.

+ 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