+ Reply to Thread
Results 1 to 12 of 12

Assign the name to the sheet of the region selected not sheet1, sheet2 etc.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-23-2012
    Location
    Pakistan
    MS-Off Ver
    Microsoft office LTSC professional plus 2021 version 2403 (Build 17425.20176)
    Posts
    378

    Assign the name to the sheet of the region selected not sheet1, sheet2 etc.

    in the attachment, when i choose a region from the drop down and then click on the shortcut created in the sheet, it extracts the data into a new sheet of the region selected,

    REQUIRED: when I run the macro it must assign the newly created sheet name of the region selected.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Assign the name to the sheet of the region selected not sheet1, sheet2 etc.

    Change
    Sheets.Add
    to
    Sheets.Add.Name = Sheet4.Range("L2")
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Assign the name to the sheet of the region selected not sheet1, sheet2 etc.

    @ sintek,

    Hi my Vriend,

    Jy sal eers 'n kontrole kode moet byvoeg om te bevestig dat die Blad nie alreeds bestaan nie.

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,027

    Re: Assign the name to the sheet of the region selected not sheet1, sheet2 etc.

    Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your "extract on a new sheet" sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make e selection in L2.
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Intersect(Target, Range("L2")) Is Nothing Then Exit Sub
        Application.ScreenUpdating = False
        Dim LastRow As Long
        LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Range("A3:J" & LastRow).AutoFilter Field:=3, Criteria1:=Target
        Sheets.Add(After:=Sheets(Sheets.Count)).Name = Target.Value
        Range("A4:J" & LastRow).SpecialCells(xlCellTypeVisible).Copy Sheets(Target.Value).Cells(1, 1)
        Sheets("extract on a new sheet").ShowAllData
        Application.ScreenUpdating = True
    End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  5. #5
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Assign the name to the sheet of the region selected not sheet1, sheet2 etc.

    @ Mumps1,

    And what will happen if the Sheet to be created already exists?

    Regards.

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Assign the name to the sheet of the region selected not sheet1, sheet2 etc.

    @ Winon

    Hi daar ou mater...Long time no hear....
    Not sure if OP would require....This surely would mean that the info would change all the time and he would have to copy to nextrow...


    Edit...A workaround ?
    Option Explicit
    Sub Region_Wise_Data()
    Dim ws As Worksheet, exists As Boolean, nRow As Long
    exists = True
    Application.ScreenUpdating = False
    With Sheet4
        With .Range("A3:J" & .Cells(Rows.Count, "J").End(xlUp).Row)
            .AutoFilter
            .AutoFilter Field:=3, Criteria1:=Sheet4.Range("L2")
            .SpecialCells(xlCellTypeVisible).Copy
        End With
        If Not Evaluate("ISREF('" & [L2] & "'!L2)") Then exists = False
        If exists = False Then
            Sheets.Add.Name = .Range("L2")
            ActiveSheet.Paste
        Else
            MsgBox "Sheet exists, Info will be copied to next available row", vbInformation, ""
            With Sheets(Sheet4.Range("L2").Value)
                nRow = .Cells(Rows.Count, "A").End(xlUp).Row + 1
                .Range("A" & nRow).PasteSpecial xlPasteValues
            End With
        End If
        .Activate
        .ShowAllData
    End With
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    End Sub
    Last edited by Sintek; 12-20-2017 at 02:30 PM.

  7. #7
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Assign the name to the sheet of the region selected not sheet1, sheet2 etc.

    @ sintek,

    Now that is more like how I got to know you. Much better Coding solution!

    Groete,

    W

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Assign the name to the sheet of the region selected not sheet1, sheet2 etc.

    oops...omitted red in above lol

  9. #9
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,027

    Re: Assign the name to the sheet of the region selected not sheet1, sheet2 etc.

    @Winon: I just followed the code in the file attached to Post #1. If geniusufo007 has a problem with the sheet already existing, I can easily modify the macro I suggested to take care of the problem. I believe that a Worksheet_Change event is probably the most efficient way to handle the original request.
    @geniusufo007: Please let me know how it works out and if there is a possibilty that the sheet already exists.

  10. #10
    Forum Contributor
    Join Date
    12-23-2012
    Location
    Pakistan
    MS-Off Ver
    Microsoft office LTSC professional plus 2021 version 2403 (Build 17425.20176)
    Posts
    378

    Re: Assign the name to the sheet of the region selected not sheet1, sheet2 etc.

    thanks ALL specially Mr. sintek for your code

  11. #11
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Assign the name to the sheet of the region selected not sheet1, sheet2 etc.

    Glad I could contribute...Tx for rep +

  12. #12
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Assign the name to the sheet of the region selected not sheet1, sheet2 etc.

    @ sintek,

    Heck, you were one ahead of me, as I was going to try and solve this issue for the OP.

    Well done!

    Mooi bly,

    W.

+ 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. [SOLVED] Copy selected data from sheet1 to sheet2
    By Rajesh shishodia in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-03-2015, 06:20 AM
  2. [SOLVED] A macro which pulls the data from sheet2 to sheet1 basis of scenarios selected in sheet1
    By Manish_Gupta in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-15-2015, 01:46 PM
  3. How to transfer selected range from sheet1 to sheet2
    By arunrana2004 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2014, 12:23 PM
  4. Replies: 6
    Last Post: 07-25-2013, 02:58 PM
  5. [SOLVED] Copy Selected Rows from Sheet1 to Sheet2
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 08-08-2012, 05:34 AM
  6. Moving selected rows from Sheet1 to Sheet2
    By guerreiropequeno in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-04-2011, 03:57 AM
  7. Cut selected value frm sheet1 & paste value to sheet2
    By bernardng in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-04-2006, 11:56 AM

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