Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Sort Excel Sheets In Custom Order Based On Value In A List

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0

    Sort Excel Sheets In Custom Order Based On Value In A List

    Hi Everyone,

    I have workbook which has 40 sheets, i want to place/move all the sheets in order as per the list of value in sheet1.
    Note: Sheet names are different . i want to move the sheets from the value you place in sheet1, the value will be there in some sheet. So that sheet should move as per the list in sheet1

    EG:
    In Sheet 1 -- i am placing value in B2 column 20, 10, 30. And there are Three sheets named as A, B, C. In Sheet "A" in cell B2 the value 10 is there, In "B" sheet contain a value 20 in b2, In sheet "C" , B2 contain 30.
    When i place 20,10,30 in sheet1, the sheet which cotains the values need to moved as per the list.


    Can you please help to wirte macro or VB code.

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Can be done naveenroy. But just to be sure exactly how you want the output, can you post a sample file that has the expected output, after macro will be run.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0
    Hi ,

    Thanks for the quick reply. I need an out put like this.

    Basically i have 35 sheets. In Every sheet at B2 cell there Project ID. I want to get all the project Id's of all sheets in the sheet1 of B column . And then in C Column i will be Prioritize like 1,2,3 etc and move the sheets as per priority.

    So on click of button a need all Projects in Sheet1 of B column, after i prioritize in C column (1,2,3) Sheets need to moved as prioirtize

    Example:
    Sheet1:
    B C
    100 2
    200 1
    500 3

    Note : Sheets names are Project's Names

    ** Iam not able to attach the excel. let me know how to attach tht excel

  4. #4
    Junior Member
    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0
    Need another automation which is very similar to the above .

    I have 35 worksheets. When i put the Projects ID's in B2 to b36 (List) of Sheet1. (The projects ID will be there in any of 35 sheets) After finding projects ID in any sheet that sheet need to moved as per the list in the workbook.

    Note: All sheets are names as Project name's

  5. #5
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    To attach a file, please go to the advanced edit options. The scroll down a bit, and you'll find the attachment button. You can upload a file within certain size limits. If the file size is beyond the forum limit, you can upload the file to any fileshare sites, and then post a link here.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  6. #6
    Junior Member
    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0
    Please find the attachment.

    As in the sheet1 there are value which will be there in any of the sheets A or B or C sheet.
    eg: So output should be in sheet1 20,10,30(which i will be puting the value in any order) so in First place/move the sheet which contain 20 to be first sheet and secong sheet which contain 10 and so on..
    Attached Files Attached Files

  7. #7
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Try this

    Code:
    Sub MoveSheetAround()
    
        Dim lng As Long
        Dim wks As Worksheet
        Dim lngCrVlu As Long
        Dim rng As Range
        With Worksheets("Sheet1")
            Set rng = .Range("A2:A" & .Cells(Rows.Count, 1).End(xlUp).Row)
        End With
        For lng = 1 To rng.Rows.Count
            For Each wks In ThisWorkbook.Worksheets
                If wks.Name <> "Sheet1" And wks.Cells(2, 2).Value = rng.Cells(lng).Value Then
                    wks.Move After:=ThisWorkbook.Sheets(lng + 1)
                    Exit For
                End If
            Next wks
        Next lng
        
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  8. #8
    Junior Member
    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0
    Thanks So much for the code. Its running in tht sheet
    But i am not able to run in my actual sheet of mine plz find the sheet in the link

    https://www.box.com/s/mkhnxvfj96a8kx6lh3e2

  9. #9
    Moderator
    Join Date
    Jul 2012
    Posts
    156
    Rep Power
    12
    Code:
    Sub MoveSheetAround()
    
        Dim lng As Long
        Dim wks As Worksheet
        Dim lngCrVlu As Long
        Dim rng As Range
        With Worksheets("Sheet1")
            Set rng = .Range("A2:A" & .Cells(Rows.Count, 1).End(xlUp).Row)
        End With
        For lng = 1 To rng.Rows.Count
            For Each wks In ThisWorkbook.Worksheets
                If wks.Name <> "Sheet1" And wks.Cells(5, 3).Value = rng.Cells(lng).Value Then
                    wks.Move After:=ThisWorkbook.Sheets(lng + 2)
                    Exit For
                End If
            Next wks
        Next lng
        
    End Sub

  10. #10
    Junior Member
    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0
    Thanks so much Simply Great!! Thanks so much for your help.
    Just small Clarification

    In the code :

    in If condition it refers to C5, i also want to refer B5 if that number is in the list.



    https://www.box.com/s/bs98wqyaw3ahvv348nc1

Similar Threads

  1. How to Add Custom List And Use in Custom Sorting
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 06-07-2013, 10:41 PM
  2. Replies: 1
    Last Post: 05-03-2013, 04:41 PM
  3. List of files in chronological order
    By Rasm in forum Excel Help
    Replies: 2
    Last Post: 11-12-2012, 10:16 PM
  4. Custom Spin Button Based On Values Passed From Array
    By Preeti Verma in forum Excel Help
    Replies: 7
    Last Post: 05-22-2012, 07:23 PM
  5. Printing Sheets Based On Criteria VBA
    By excel_learner in forum Excel Help
    Replies: 1
    Last Post: 05-04-2011, 08:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •