+ Reply to Thread
Results 1 to 79 of 79

Sorting with vba loop?

  1. #1
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Sorting with vba loop?

    Hi I have a lot of data stored in column B:G coloumn B I have sorted and copied (+removed duplicates) over to column N

    Im trying to sort this in a special manner as im gonna use this data in dynamic list

    So now I want to search for keyword N3 and get a match for all corresponding data in column C (also without no duplicates)

    here is my attempt

    Please Login or Register  to view this content.
    but this code copies to much as this gives over 50 of the same result

    any help would be much appreciated :=)

  2. #2
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Here is my updated formula:

    Please Login or Register  to view this content.
    This did indeed give me the result I desired, without removing duplicates .

    But now comes the real problem I need a this to loop trough all the data I have stored (30 countries or so)

  3. #3
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    Hi colddeck84

    please upload a sample file so that we can have a look.
    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 star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  4. #4
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Hi, Thank you for your reply. Here is an sample, the codes are in the modules

    I did not include the codes for the the main table, but this table is dynamic and will change pretty often.

    http://www.filedropper.com/samplev1

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Sorting with vba loop?

    Please upload the workbook to this forum. Many of us prefer to avoid file hosting sites of unknown (to us) provenance.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  6. #6
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    ok will do but , sorry didn't see the upload link before
    Attached Files Attached Files

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    Is this what you are trying to achieve....
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Nice good job, but its not exactly what I was going for.

    I want each league to be sorted under corresponding league, So that "super League" goes under Albania, Then Liga 1 Under Algeria, and so on

    Its actually a 2(3) problem.
    what you did should actually be sorted horizontally to the right from last column in row 3

    And Thank you for your time to help me with this .

  9. #9
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    I updated your code to this,does it look correct?

    Please Login or Register  to view this content.
    This will solve my 2nd problem

    Now I just need Leagues sorted under the different Countries

    And Home (LP) sorted under the different leagues.

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    I want each league to be sorted under corresponding league, So that "super League" goes under Albania, Then Liga 1 Under Algeria, and so on
    Please Login or Register  to view this content.
    Upload a sample with your required result depicted...even if it is only the first few rows...so that we can understand your requirement.


    EDITED: Added code
    Last edited by sintek; 05-27-2017 at 02:17 PM.

  11. #11
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Hi sorry for confusing description I added an sample_v_3

    Hope this gives an better idea how i want it?
    Attached Files Attached Files

  12. #12
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    You see the o plan is to make list(s) of this data. All of these countries, leagues and teams changes everyday

    something as shown in this sample file.
    Attached Files Attached Files

  13. #13
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    I tested your code and it does work fine., However I can see a problem right now there are only 3 Countries so the codes loops trough these.
    but it should in fact return more results as there are more then 1 league for each country

    In the uploaded sample it returns VIC, GS AND J3

    But Should also Return:

    NNSW
    ACT
    NSW
    LIGA 1
    J2

    Also I try to show in the sample how it should be sorted. If you understand

    First it should load country then Leagues

    Alse the leagues should be under the different countries, And The different teams from "column 3" should be under the different leagues

    Edit: Im not sure but I think it need to be 3 loops. Because it need to find every league for every country without duplicates , my brain melts when looking at this :/

    Also ty for all your help
    Attached Files Attached Files
    Last edited by colddeck84; 05-28-2017 at 05:10 AM.

  14. #14
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    Will have a look at it tomorrow....

  15. #15
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Ok thank you.
    really appreciate it.

  16. #16
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    Each league also has different scores..... In able for us to write the correct code we will need a complete sample depicting result..... ignore your code currently and the result it gives....make use of Sample v 4 and depict result and highlight requirement....
    Do you want the words header, first list, list1 list2 etc ......are the columns correct as you have changed over all the past uploads?

  17. #17
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Hi I have made an updated sample and sorted all the leagues manually. This is how it should be sorted with code.
    - You will see that each country has several leagues and they should be sorted under correct country

    "Each league also has different scores"
    -if you mean Score from Column F , that is not for this part

    "Do you want the words header, first list, list1 list2 etc"
    About the list 1 , 2 , 3 , etc in row 2 these were just to show you what I meant , but looks like they gave only more confusion.

    "..are the columns correct as you have changed over all the past uploads?"
    -The columns are correct. But the main table is dynamic and will change as soon as I refresh it that's why it looks different from sample to sample

    If you have any more question Ill try to answer as soon as possible.

    Edit: Sorry I didn't see that you requested that I use sample 4 as base , hope it is ok that I updated another updated one ?
    Attached Files Attached Files
    Last edited by colddeck84; 05-28-2017 at 03:27 PM.

  18. #18
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    If I understand this time round then this code should work....Not the most glamorous, but does the job....
    Perhaps another can perfect....
    Please Login or Register  to view this content.

  19. #19
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    wow that is one sick code

    Its a little strange but the code works just fine in the test sheet but in my main file when I try to load it nothing happens , you know why this could be???

    Edit nevermind , feel silly just changed sheet name..

    The code also copies the conditional formating , how do i remove this ?
    Last edited by colddeck84; 05-28-2017 at 05:01 PM.

  20. #20
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

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

  21. #21
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Works Perfect ,
    I added just something below your code yesterday to remove the format , but liked your updated code much better

  22. #22
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Would it be possible with a fellow up question ? as I see you formula was way to complicate for me to duplicate. I was hoping to get an working code for the league and teams also..
    this will be a little different requirements as teams from column "E" and "G" needs to be sorted under correct header

    I have attached a wb on how it should look. I hope i don't push the line with asking for more help..
    Attached Files Attached Files

  23. #23
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    This will solve the second part of the attached....
    Please Login or Register  to view this content.

  24. #24
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Hi nice you made it real quick , however I think i made some mistake again but I'm not able to get it to work, I adjusted the code to this:

    Please Login or Register  to view this content.
    I made this adjustment in red , but no luck :/

    also regarding the var I , its set as start num 20 but shouldn't this be a a dynamic num like lastrow or column ?

  25. #25
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    adjustment in red , but no luck
    Try declare your sheet, unless the Tab name has a blank somewhere ....This happens often when you type the name....
    Please Login or Register  to view this content.
    regarding the var I , its set as start num 20 but shouldn't this be a a dynamic num like lastrow or column
    Of course...did not take that into account.

  26. #26
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    I tried your suggested updates.
    but still no luck.

    [edit]
    it does however work on the sample 6 file. maybe its the i var that is the problem ?
    Last edited by colddeck84; 05-29-2017 at 02:49 PM.

  27. #27
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    Here is the entire code taking the i Var into account:
    Please Login or Register  to view this content.
    I tried your suggested updates.
    but still no luck.
    Is there a error or does it not do what you require

  28. #28
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    it does what i require ., see my edited post above.

    but it does not give any results with updated main table.

  29. #29
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    And the combined code in post 27

  30. #30
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    I did not see the code in post 27 , I just tested it, but it only returns From column D

    - basically returns the same as code: trysort ()

    Maybe it does not work as the leagues are not sorted horizontally like the were in the sample file *?

    (edit)

    tested and can confirm it does not work since the league are not sorted horizontally from last column and to the right -

    This has become one real beast code is it possible you could assist in making this final adjustment ?
    Last edited by colddeck84; 05-29-2017 at 03:20 PM.

  31. #31
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    Well there's your problem...Code is written for your uploads....

  32. #32
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    I understand if you don´t want to , you have already been more then great

    I guess I´ll try to add this myself, its just a little hard to figure where to add it into your ninja code

  33. #33
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    You will have to upload the file you are working on.....so that I can have a look

  34. #34
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    This part is missing in your final ()

    Please Login or Register  to view this content.
    This code will add all the leagues , just need to integrate it into your master code

  35. #35
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    I'm so confused!!!
    You've uploaded 6 versions..... Don't understand what you want to do....What does your sheet you are working with look like....What columns are populated prior to code running....Want to assist but need a final sample from you.....with std info in black and result in highlighted yellow....

  36. #36
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    I know im bad at explaining things :/
    , IM not sure im confortable sharing my main sheet as this contains some sensitive data besides this work.

    Ill try my best;

    ".What does your sheet you are working with look like"

    Looks exactly as the sample file only it contains an button to update the main table

    ".What columns are populated prior to code running"

    - Main table is populated by btn get result (CoulomB:G)
    - Column N iis populated by another btn: Countries
    this data is also sorted horizontally from column 0 to the right
    - Latest code I posted here will populate leagues (what was missing, but i had entered manualy in test sheet"

    Basically This code (also based on your work) , needs to merge with your final (): and that is it.

    Remove column T-X to test in sample_v_6 to test

  37. #37
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    Right....Have a look at this Final version I uploaded....If not right now then I'm at a loss if I can't see your actual workbook....
    Push Stage1 then Stage2
    Stage 1 is your code which I adapted....Did not neaten up unfortunately.
    Stage 2 the rest
    Attached Files Attached Files

  38. #38
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Yes this is correct, its one sick code

    - I was able to get all the desired results. But I think there is something wrong with one Var because when I refreshed the main table something went wrong. I will see if I can try to upload the main sheet.

    I think maybe this one

    Please Login or Register  to view this content.
    Thanks for all your help with this

    Think i will need to rebuild the code that sort the leagues other then that your latest code works perfect
    Last edited by colddeck84; 05-30-2017 at 12:17 AM.

  39. #39
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    I've tested on all your sample uploads and it seems to work...

  40. #40
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254
    Quote Originally Posted by sintek View Post
    I've tested on all your sample uploads and it seems to work...
    OK Nice, I did just check real quick this morning will do further testing later after job.

  41. #41
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Hi I just came home tested in main sheet everthing works as expected , This is so great , you would not belive how much work this code saves me for (earlier I entered every all the information from this code manuay) tgis is pure GOLD

    I don't know how to thank you enough , you are just the best

    (as a side note , reson it did not work foir me was that i didn't copy both of your modules just the final() )


    Anyway thanks

  42. #42
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    Glad you got it working...Now we can finally mark as solved....Thanks for rep point

  43. #43
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Ouch im sorry to report that the code makes (some) duplicates, not with the teams but with the leagues
    and also its seams almost random what is duplicated, around 10-20% or so ??? really crazy

    Here is results it generated from russia.

    Professional Football League Ural-povolzhye
    Professional Football League West
    Professional Football League South
    Professional Football League Ural-povolzhye
    Professional Football League West
    Professional Football League South


    Maybe there is an simple code I can add at the end , where it searches for duplicates and as maybe sort it A to Z

  44. #44
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    The code was written for all your uploads and works perfectly!!!!
    Other than your actual workbook upload I cannot assist.
    Maybe there is an simple code I can add at the end , where it searches for duplicates and as maybe sort it A to Z
    Stay clear from quick fixes and rather solve the problem.

  45. #45
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    colddeck84

    See if the result is how you wanted or not.
    Please Login or Register  to view this content.

  46. #46
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    Have you checked your spelling..Perhaps an error causing duplicates...
    PS....Awesome code of jindon's for your first part...Perhaps he can perfect the second part as well...He is a genius...

  47. #47
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Hi I just came home from work, maybe ill stay away from the quick fixas you suggested.

    "have you checked your spelling..Perhaps an error causing duplicates..."
    -I can confirm after testing some that there is something going on with horizontal league sorting as it generates a couple duplicates , im really sorry to say this
    I added country name to the lewague name to see as there weere some leagues with same name, but still same results with unique league name.

    Also hi jindon, ty for your help. I have not near the same expertise as your guys and the code is already to complicated for me.
    Wheere should I insert your line of code ?

  48. #48
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    I wrote the code based on your workbook in post #5.
    Attached Files Attached Files

  49. #49
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Its no joke that you are a genius I can tell Your code was lightning fast, load time went down from 2-3 sec to about 0,00000001
    But for this part of the code there was working fine , maybe just a little slow, It is only the second part of the code there is some problem with
    : The one that adds the teams under the leagues

    I really liked your work on this , would it be possible that you could update this to also load the Leagues after country and teams under (also it would be great that it just make one new sheet and never again)

    As a side question. After I started working with this code I get this error when loading my sheet_

    "we found a problem with some content in "file name" Do you want us to try to recover as much as we can? "

    After clicking yes I get an error in sheet4.bin (which I dont have even"
    Earlier it was in sheet 5 ., But I deleted this sheet and everything was fine four a very short while,
    Maybe you guys have experienced something like this before ?

  50. #50
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    If you upload a workbook with before/after clearly showing the logic behind it, it would help me to understand your problem.

    It should not a big data but should be Exact result, do not just enter something like "etc".

    So that I can take a look at it tomorrow.

  51. #51
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Sorting with vba loop?

    Its no joke that you are a genius I can tell
    Told you so...lol....If only i came close...but hey baby steps...I still don't understand jindon's designer code....
    Wish he came in earlier would have saved us both a headache...lol

  52. #52
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Quote Originally Posted by jindon View Post
    If you upload a workbook with before/after clearly showing the logic behind it, it would help me to understand your problem.

    It should not a big data but should be Exact result, do not just enter something like "etc".

    So that I can take a look at it tomorrow.
    I appreciate that alot , Ill try to upload the entire code so you can generate the list as well :=)

  53. #53
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Hi I was not able to copy any of the code over to this document :/ I ran into to many problems.

    But its uploaded with all the results from previous help.

    * You will see that something goes wrong in this code as several leagues are duplicated :/

    *not sure what that has happened here , other then the duplicate issue code is working fine sorting it like it should , I do not think any of the teams are duplicated,

    Hope this is ok to understand, but it would be much better that you move all of the data that the sort code generates into a new sheet "Data" (but always this sheet)

    The point with all of this sorting is to make list(s) out of everything:

    List 0 will be sport
    List1 (dependent upon list 0) will be Country:
    List2 (dependent upon list1) will be league
    List 3 (dependent upon list2) will be teams

    (All the list making I think I can handle myself)

    Edit: Uploaded sample with unique league name(s)
    (use v 8.1.1)
    Attached Files Attached Files
    Last edited by colddeck84; 05-31-2017 at 04:16 PM.

  54. #54
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Hi did you get any chance to look at this ?

    or maybe the sample file was not good enough ?

  55. #55
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    Is the data in N2:FT40 in "test" sheet your desired result?

    If so, take Argentina

    Your result shows
    (AR) Primera Division
    (AR) Primera B Nacional
    (AR) Primera Division
    (AR) Primera B Nacional
    (AR) Primera Division
    (AR) Primera B Nacional
    (AR) Primera Division


    Where as my result
    (AR) Primera Division
    (AR) Primera B Nacional

    Do you want not just a unique , but all of them?
    If so, change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  56. #56
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    " the data in N2:FT40 in "test" sheet your desired result?"

    If so, take Argentina - Your results is what im interested in , but you code stops after sorting leagues under countries-

    Problem Comes with step 2 of the code which Sintek helped me compile.

    In step 2 of the code it should add all the leagues starting from last column , in test sheet this is BA and add them to the right so in the test sheet this is BA:FS
    and also load the teams under the leagues (quite similar to step one) , only difference is that data for the teams is fetched from 2 columns : E ang G. Sinteks code does this , but for some reason his code creates a couple of duplicated results of the leagues.

    I hope I not explained it to confusing as explaining is not my strongest suit

  57. #57
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    Number of columns are differ from yours, so check what I missed.
    Please Login or Register  to view this content.

  58. #58
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254
    I'll run the code, should I first run your first code or just the latest?

  59. #59
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    Just latest.

    P.S the result will appear from N2 in new sheet.

  60. #60
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Boom loaded everything in less then a second. You have crazy skills with this , it even didn't take you long for you to compile this and with that vague description as well
    Very good job Sir

    Could I please ask for two slight modifications ?

    1. That it loadlike this A1="#" A2:A & Last row = Countries , B1: Last Column & row 1 = First countries then Leagues
    And all the Data under , Almost exactly as you made your first code , except this code also have the league and teams sorted.

    2. That all of this data is always generated to same sheet "LeagueDataOrSomething" , Then it will be super easy for me to find all of this information to load into my lists

  61. #61
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    Upload a workbook showing exact result that you want.

  62. #62
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    I uploaded a sample here , I included your code in the button sort , And I renamed the sheet where all want all the data loaded to "leaguedata" ,
    would be great that your code clears this sheet then loads the data , always in this sheet and never a new sheet.
    Attached Files Attached Files

  63. #63
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    Change to
    Please Login or Register  to view this content.

  64. #64
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Hi I just tested it

    It was able to sort data, from 1-6 of june without any problems.
    Very good job indeed, Thanks alot for all you help. This is some crazy code its not like anything I have seen in these forums before,.
    Last edited by colddeck84; 06-01-2017 at 03:59 PM.

  65. #65
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    If that takes care of your original question, select Thread Tools from the menu link above and mark this thread as SOLVED.

  66. #66
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Done , thanks alot for your help with this , your ninja code really helped

    Also big thanks to sintek for his time and effort

  67. #67
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Hi I ran into one small problem with your sort code, you see that coloumn F in the main sheet "score" in all samples has returned just this "-", buyt if I change some of my settings this coloumn will desplay the ft result like "2-0" "3-1" , somehow this gives this line problems in your code:

    Please Login or Register  to view this content.
    is there an simple fix for this?

  68. #68
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    No idea, because my code is nothing to do with Col.F in "test" sheet.

  69. #69
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Hi thanks for your swift reply . That's also what I thought was weird , but as soon as I fill column F with results I get this error msg:

    Run-time error 9
    Subscript out of range

  70. #70
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    Upload a workbook.

    Guess game is no fun.

  71. #71
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    I have uploaded 2 workbooks:

    - The content for the one with error is matches from today , (both finished and not finished matches) - this results to some error in your code.

    - The 2nd version are finished matches from yesterday - this file gives no errors , I don't know why

  72. #72
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    Both no error and the code is not the latest one.

  73. #73
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Oh sorry I did not include any code in it ... Just a moment ill add it

    Edit: done
    Attached Files Attached Files
    Last edited by colddeck84; 06-03-2017 at 06:02 AM.

  74. #74
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    When you change the putput sheet, you must prepare the sheet named "Lists" in this case.
    Please Login or Register  to view this content.

  75. #75
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    It was just for the sample I forget to change this, look at this sample :
    Attached Files Attached Files

  76. #76
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    BTW, do you need a vertical list of country? meaningless to me.

  77. #77
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    Hi thanks for your help, I guess it looks meaningless for this code, - but your code is used for something else where country is sorted in a list (master) then the other info is dependent upon this

    I added a screenshot , all of this is possible thanks to your help
    Attached Images Attached Images

  78. #78
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Sorting with vba loop?

    Quote Originally Posted by colddeck84 View Post
    but your code is used for something else where country is sorted in a list (master) then the other info is dependent upon this
    Absolutely NO!.
    When I first looked at this thread in you first post, I didn't understand the necessity of this vertical country list and I thought it would something to do with the matrix work.
    So, I didn't answer at the first time.

  79. #79
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Sorting with vba loop?

    im not sure what you said no to ? hope your not mad ?

    - I'm really grateful for your provided help - I'm super happy with the end result

+ 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] VBA to loop within a loop of multiple blocks of data (currentregion) ... Expert needed
    By Jim885 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-20-2016, 08:28 PM
  2. Loop runs stuck with sorting
    By nielsBNP in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-17-2013, 10:04 AM
  3. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  4. Help with sorting data and copy/pasting a range instead of a loop check for each row
    By Pwincu20 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-14-2012, 03:01 PM
  5. Help with using sorting fields by date within an existing loop statement
    By jc0045 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-04-2011, 02:30 PM
  6. Do while loop and date sorting
    By excel_sunsan in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-19-2010, 11:48 PM
  7. Do while loop sorting data
    By gwithey in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-31-2008, 08:57 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