+ Reply to Thread
Results 1 to 16 of 16

Macro to reorder entries in a single cell

  1. #1
    Registered User
    Join Date
    08-09-2012
    Location
    Norfolk,va
    MS-Off Ver
    Excel 2007
    Posts
    15

    Macro to reorder entries in a single cell

    I have a template that made for work and i have a few cells that anywhere from 1 to 4 entries in them. I need to reorder those entries in a set order of priority. If i was only going to do is a few time i would just do it by hand but i have 200+ of this templates to go through every month so a macro would help. The cells in question are D4-D22. I can't put the full template up bc of some of the info on it but i have a copy of the worksheet in question. The set order i would need it in is 2L4,2L5,2L3,2A3,1A1,1A2,1A3,1A9,1A4,1A7,1P0,2R1,2R2.
    Help.xlsx

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

    Re: Macro to reorder entries in a single cell

    Hey there,

    Try this:

    Dim Arr(), LR As String, ws As Worksheet 'declare variables

    'add custom list equal to the array defined in order of the values listed in your thread
    Application.AddCustomList ListArray:=Array("2L4", "2L5", "2L3", "2A3", "1A1", "1A2", "1A3", "1A9", "1A4", "1A7", "1P0", "2R1", "2R2")

    Please Login or Register  to view this content.
    To insert this code into your workbook

    1.Press Alt+F8 on your keyboard
    2.Clear the macro name box and type SortByCustom in the blank box provided
    3.Select the Create option
    4.In between the Sub SortByCustom() and End Sub copy and paste the above code
    5.Exit out of the Visual Basic Window
    6.Press Alt+F8 again and this time select the SortByCustom macro
    7.Select Run

    Please note: This code assumes you do not want to skip any worksheets and that there is no data below the Totals row.

    Let me know if this works for you.


    Let me know how these work for you!

  3. #3
    Registered User
    Join Date
    08-09-2012
    Location
    Norfolk,va
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Macro to reorder entries in a single cell

    I will Run this in the base template i pasted on here to see how it works. On the real template this is the second worksheet of 3 i only need it for the 2nd worksheet. not sure how that changes.

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

    Re: Macro to reorder entries in a single cell

    Here you go:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-09-2012
    Location
    Norfolk,va
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Macro to reorder entries in a single cell

    Really new to macros/VBA's where am i putting this part???

    Please Login or Register  to view this content.
    Last edited by Cutter; 08-13-2012 at 12:02 PM. Reason: Added code tags

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

    Re: Macro to reorder entries in a single cell

    Hello there,

    Your entire macro should look like this

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-09-2012
    Location
    Norfolk,va
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Macro to reorder entries in a single cell

    It works but i am thinking what was not clear with what i need. i only need the data in the cell reordered not the cell's reordered themselves. Sorry i was unclear but it works like a champ for what it does.

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

    Re: Macro to reorder entries in a single cell

    Whoops sorry about that. Okay let's try this one:

    Please Login or Register  to view this content.
    Use the above steps naming the macro a different name this time then the one I provided you earlier.

    Let me know if this is what you were looking for. You'll need to select the sheet before attempting to run the code.

  9. #9
    Registered User
    Join Date
    08-09-2012
    Location
    Norfolk,va
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Macro to reorder entries in a single cell

    is the part about only the second worksheet in this one. I may have just missed it.

  10. #10
    Registered User
    Join Date
    08-09-2012
    Location
    Norfolk,va
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Macro to reorder entries in a single cell

    Getting a few errors when i try and run it but i am thinking i messed something up.

    Please Login or Register  to view this content.
    Last edited by Cutter; 08-13-2012 at 12:03 PM. Reason: Added code tags

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

    Re: Macro to reorder entries in a single cell

    When the error comes up and you press Debug what line is highlighted in the code?

  12. #12
    Registered User
    Join Date
    08-09-2012
    Location
    Norfolk,va
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Macro to reorder entries in a single cell

    Please Login or Register  to view this content.
    Last edited by Cutter; 08-13-2012 at 12:03 PM. Reason: Added code tags

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

    Re: Macro to reorder entries in a single cell

    Alright,

    Attached is the workbook you provided in your first post with the code. It works from my end, try running the macro SortD by enabling macros, press Alt+F8, and select the SortD macro and click Run.

    Let me know if this works.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    08-09-2012
    Location
    Norfolk,va
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Macro to reorder entries in a single cell

    Works Great thank you Very much for all your help.

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

    Re: Macro to reorder entries in a single cell

    No problem, don't forget to mark this thread solved and maybe if I helped give a little star tap.

    Thanks!

  16. #16
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Macro to reorder entries in a single cell

    @ willi_42

    Welcome to the forum.

    Please notice that code tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at top of the page and read Rule #3.
    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