+ Reply to Thread
Results 1 to 18 of 18

How write sheets array to sort multiple worksheet in the column

  1. #1
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    How write sheets array to sort multiple worksheet in the column

    Hi,

    Can anyone help me to write sheets array?

    I have 7 worksheets to sort out i.e. sheets "ATM", "BRUN", "CAMB", "PAPU", "LAOS", "LOND", "VIET",


    Here is the sample of sheets("ATM"),
    ---------------------------------
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 04-01-2014 at 12:11 AM. Reason: Added Code Tags

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: How write sheets array to sort multiple worksheet in the column

    Faridwahidi.
    Please read the Forum Rules regarding Code Tags (#3).

  3. #3
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: How write sheets array to sort multiple worksheet in the column

    Please Login or Register  to view this content.

    sorry, I am a new forum member. code tags done, can you help me to resolve my problem

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: How write sheets array to sort multiple worksheet in the column

    Try this on a copy of your workbook
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: How write sheets array to sort multiple worksheet in the column

    Hi,

    I have copy and pasted to my VBA template but when I click to run the programme, nothing happened.


    what i want to do is to sort out Range("A2:AN") with bottom limit e1 = Range("I15000").End(xlUp).ROW


    for column M and N in descending order , then do numbering in column "O"

    next, column N and M in descending order, then do numbering in column "P"


    regards,
    farid

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: How write sheets array to sort multiple worksheet in the column

    farid
    It works for me. It sorts columns A to N in descending order starting at row 2.
    Are the sheets named properly, like no trailing spaces?
    Don't know what you mean by "do numbering" (in column O and P)
    What does "Bottom limit e1 = Range(I15000").End(xlUp).Row mean?
    I interpeted as meaning that we use Column I to find the last used cell. Is that right?
    John

  7. #7
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: How write sheets array to sort multiple worksheet in the column

    Please Login or Register  to view this content.
    Hi Jolivanes,

    Yes, your programme works for the 1st sorting only, 1st key: Column("M") descending, 2nd Key: Column("N") descending


    But does work for the next sorting 1st key change to: Column("N") descending, 2nd Key: Column("M") descending




    After the 1st sorting, I need to fill numbering in column("O") which defined as follow
    Range("O2").FormulaR1C1 = "1"
    Range("O3").FormulaR1C1 = "2"
    Range("O2:O3").AutoFill Destination:=Range("O2:O" & Range("I" & Rows.Count).End(xlUp).ROW)


    Then, after the 2nd sorting, I need to fill numbering in column("O") which defined as follow
    Range("P2").FormulaR1C1 = "1"
    Range("P3").FormulaR1C1 = "2"
    Range("P2:P3").AutoFill Destination:=Range("P2:P" & Range("I" & Rows.Count).End(xlUp).ROW)


    I attached herewith my working files for your verification. you can run my programme sub_sort() to see what happened


    Thanks for willing to assist me. really appreaciate.

    Regards,
    Farid
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: How write sheets array to sort multiple worksheet in the column

    Sorry, does NOT work for the next sorting

  9. #9
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: How write sheets array to sort multiple worksheet in the column

    Let me get this straight.
    You first want to sort as with my code.
    After that, you want to enter values in Column O, starting at O2 and down to the last used row increasing the value by 1.
    Then sort again, with Column N as the 1st Key and Column M as the 2nd Key.
    After that enter values in Column P (you mentioned Column O which I assume is a slip of the finger), starting at P2 and down to the last used row increasing by 1.
    Is that right?
    Did you plan on writing a lot of code in the 42 modules in you attached workbook?
    Last edited by jolivanes; 04-02-2014 at 01:16 AM.

  10. #10
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: How write sheets array to sort multiple worksheet in the column

    I think I might have just got it.
    You want two macros, not just one.
    One for viewing "Uptime Rank" and the other macro for viewing "Useage Rank", is that right?
    Let us know.

  11. #11
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: How write sheets array to sort multiple worksheet in the column

    Hi jolivanes,


    Yes, that is what i want to create. to avoid repeating script.

    Hopefully u can assist me to simplify the script.


    Thanks for your kind assistance.


    Regards,
    Farid.

  12. #12
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: How write sheets array to sort multiple worksheet in the column

    Try the attached.
    It has 2 macros, one for each scenario.
    I took the array out because you have a different amount of sheets as mentioned in your first post.
    Let us know if this is what you had in mind.
    Good luck
    John
    Attached Files Attached Files

  13. #13
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: How write sheets array to sort multiple worksheet in the column

    Hi ,

    Thanks, you are excellent, It works

    One more question to ask,

    Since you have created For i = 1 To Sheets.Count to represent all worksheets in the workbook.

    If there are any worksheets in the workbook should be excluded from perform sorting, How to write the sheets array,



    Thank you.

  14. #14
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: How write sheets array to sort multiple worksheet in the column

    You can put all the sheets in an array but if one of the sheets is missing it will error.
    If you have more sheets than what is in an array, they will not be included.

    You can also write code in which it excludes certain sheets by name or by index number.
    For instance all sheets except the first sheet or the first two sheets etc.
    Or all sheets except a sheet named "HONK" and a sheet named "PHIL".

    You could also put all the sheets in an array beforehand, with code.

    Or maybe the best solution, by the sound of it, is to just run it on a selected (active) sheet.

    Let us know what you want but remember, if it is hard coded it will error when it changes.


    Please Login or Register  to view this content.

  15. #15
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: How write sheets array to sort multiple worksheet in the column

    Hi Jolivanes,

    Thanks you. good idea


    What in my mind is actually to use my previous script, which has been amended from direct record, can you assist to make it works.

    Please Login or Register  to view this content.

  16. #16
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: How write sheets array to sort multiple worksheet in the column

    If you want to continue with code that is not working, I would suggest that Google is your best friend.
    Twice you have
    Please Login or Register  to view this content.
    Using .End(xlUP) is obsolete (see the code I provided for a better solution)
    Selecting as in
    Please Login or Register  to view this content.
    is frowned upon if not really required, as it is here.

  17. #17
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: How write sheets array to sort multiple worksheet in the column

    Is this what you wanted?

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  18. #18
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: How write sheets array to sort multiple worksheet in the column

    Hi jolivanes,

    That is what I wanted,

    Thanks for your assistance & willingness to tech me how to write a good script.

    I am a newbie, have no proper learning of VBA. Most of my script are edited from direct record, that is how I learnt.

    again thanks,

    Regards,
    Farid

+ 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. For Each Loop to sort column in multiple sheets
    By kbryan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2014, 09:26 AM
  2. [SOLVED] Why doesn't Application.Index write array column to worksheet range?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-13-2013, 02:07 AM
  3. Replies: 0
    Last Post: 02-04-2013, 02:28 PM
  4. write column vector of 2D array into 1 D array
    By twd000 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-22-2010, 06:01 PM
  5. Replies: 2
    Last Post: 08-19-2006, 09:45 PM

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