+ Reply to Thread
Results 1 to 16 of 16

Copy Names That Begin with A-L

  1. #1
    Registered User
    Join Date
    09-14-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    1

    Copy Names That Begin with A-L

    Hello, I have googled the snot out of this and can't come up with an answer. I need a code that will search through B5:B40 on Sheet1, sort alphabetically, and then copy only the names that start with the letters A-L and past them into Sheet2 starting at B5. Then copy all the names from Sheet1 that start with M-Z and past them into Sheet3 starting at B5 again. Please help.

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Copy Names That Begin with A-L

    Try this

    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Copy Names That Begin with A-L

    Hello there,

    The following code should work for you:

    Please Login or Register  to view this content.
    To insert this code into your workbook
    1. Press Alt+F8
    2. Clear the macro name field and then type DistributeVal
    3. Select the create option
    4. In between the Sub DistributeVal() and End Sub copy and paste the above code. Anything that appears in green is a comment meant to help you understand.
    5. Exit out of Visual Basic
    6. Press Alt+F8
    7. Select the DistributeVal macro
    8. Select the Run option

    Let me know if this works for you.

    Thanks!

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Copy Names That Begin with A-L

    Another way based on there always being an entry for M
    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Copy Names That Begin with A-L

    option, assuming names mean words

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by watersev; 09-14-2012 at 09:44 AM.

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Copy Names That Begin with A-L

    Version 2 without the need for a name beginning with M
    Please Login or Register  to view this content.
    Last edited by Kyle123; 09-14-2012 at 09:46 AM.

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

    Re: Copy Names That Begin with A-L

    Hi Kyle!
    I tried to use your code on Watersev's sheet, but I have got an error on this line

    rng = Application.Transpose(Sheet1.Range("B4:B30").Value)

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Copy Names That Begin with A-L

    At a guess (I can't open watersev's document on my mac) he's not using an English Language version of Excel. Try changing:
    Sheet1 to Sheets(1)
    Sheet2 to Sheets(2)
    Sheet3 to Sheets(3)

  9. #9
    Forum Contributor
    Join Date
    08-22-2012
    Location
    nj, us
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: Copy Names That Begin with A-L

    on mine watersev's worked

  10. #10
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Copy Names That Begin with A-L

    @John456852

    Its not that his code dosent work, its that Kyle's code wasnt working on watersev's workbook. Kyle's code uses Sheet code names, and in waterserv's workbook sheet code names are ????1

  11. #11
    Forum Contributor
    Join Date
    08-22-2012
    Location
    nj, us
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: Copy Names That Begin with A-L

    all i see is :
    Please Login or Register  to view this content.

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Copy Names That Begin with A-L

    Thanks Mike

    John, there are several ways of referencing sheets, my code will work fine on English versions of Excel, since Watersev doesn't use an English version of Excel his sheet object names (down the left hand side of the VBA IDE in the object Explorer) are not Sheet1 Sheet2 Sheet3 etc, rather they will be named in the language of the Excel installation that he is using so the objects that I reference do not exist.

    You'll see that watersev uses an alternative style of referencing sheets Sheets(2), this uses the sheets collection to refer to a sheet and works irrespective of sheet name.

    When I post code, I generally use the vba name of the sheet (as opposed to sheets("sheetname") or Sheets(1) which both refer to the sheets collection) since it will work after changing the sheet name property and remains constant regardless of sheet inserts and deletions, referring to the collection will not.

    My suggestion above as to change the type of referencing in my code to that of the style used by watersev to remove the dependance on English Sheet names whilst using watersev's wb.

    Does that clear it up any?

  13. #13
    Forum Contributor
    Join Date
    08-22-2012
    Location
    nj, us
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: Copy Names That Begin with A-L

    Yes, it does
    so, u mean that he has sheets that aren't named"sheet1,sheet2,etc."

  14. #14
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Copy Names That Begin with A-L

    @John

    heres kyle's code with sheet index instead of code names

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    08-22-2012
    Location
    nj, us
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: Copy Names That Begin with A-L

    ok. thx .
    Last edited by JBeaucaire; 09-15-2012 at 10:00 AM.

  16. #16
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Copy Names That Begin with A-L

    Hmm?

    As a matter of interest this can be done without VBa, might be handy when macros are not allowed, or for proud mac owners running a version that doesn't support VBa.

    See this workbook sorting text with formulae should be of interest to most.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

+ 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