+ Reply to Thread
Results 1 to 32 of 32

Populate each item to proper place

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Populate each item to proper place

    Hello everyone
    I have names and each name has some wishes (sections desired are four : Range("M12:M15"))
    The distribution would be according to the highest marks and limited to the maximum number allowed for each section which is in range("N12:N15")

    Note that the wishes in columns("F:I") are important .. I mean may be someone has high mark but his wish "Trade" for example so the wish should be put in mind .

    I attached the expected output to illustrate my issue
    Attached Files Attached Files
    Last edited by YasserKhalil; 07-18-2015 at 04:34 AM.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    I tried to solve the problem step by step by formulas as illustrated in sheet1 ...
    Please see the attachment, it may help to solve the problem.
    Forget the attachment in post 1 .. I figured it in a wrong way
    Focus now on the attachment in this post
    Attached Files Attached Files

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: Populate each item to proper place

    I've looked at your post and explanation in post 1. I've also looked at your file in post 2. I do not understand what you are attempting to do. Please clarify in simple language. Explain it to me like we were standing in line in a coffee shop.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Populate each item to proper place

    Row\Col
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    2
    Who
    Moh Mwared Tas Trade D2:G3: Input
    3
    Max
    7
    6
    5
    2
    4
    Assigned
    7
    6
    5
    2
    D4: =COUNTIF($H$7:$H$26, D2)
    5
    6
    Score
    Name
    1st Pref
    2nd Pref
    3rd Pref
    4th Pref
    Assign
    Pref
    7
    15.4225
    Alan Moh Tas Mwared Trade Moh
    1
    B7:G26: Input
    8
    15.3375
    Barb Trade Tas Mwared Moh Trade
    1
    H7: {=INDEX(D7:G7, MATCH(TRUE, COUNTIF(H$6:relN, D7:G7) < LOOKUP(D7:G7, $D$2:$G$3), 0))}
    9
    13.4075
    Cain Tas Moh Mwared Trade Tas
    1
    I7: =MATCH(H7, D7:G7, 0)
    10
    13.3425
    Dana Trade Tas Moh Mwared Trade
    1
    11
    13.2600
    Eric Trade Mwared Moh Tas Mwared
    2
    12
    13.1550
    Fran Tas Moh Trade Mwared Tas
    1
    13
    13.1450
    Gary Mwared Trade Tas Moh Mwared
    1
    14
    13.1275
    Hana Mwared Tas Moh Trade Mwared
    1
    15
    13.1250
    Ivan Tas Mwared Trade Moh Tas
    1
    16
    12.9375
    Jane Moh Mwared Trade Tas Moh
    1
    17
    12.8450
    Kent Trade Moh Mwared Tas Moh
    2
    18
    15.2650
    Leah Moh Mwared Trade Tas Moh
    1
    19
    14.8700
    Mark Tas Moh Mwared Trade Tas
    1
    20
    14.2750
    Nina Mwared Tas Moh Trade Mwared
    1
    21
    14.2450
    Otto Mwared Tas Trade Moh Mwared
    1
    22
    14.1775
    Peri Moh Mwared Trade Tas Moh
    1
    23
    13.9675
    Quin Tas Trade Moh Mwared Tas
    1
    24
    13.6500
    Rene Tas Trade Mwared Moh Mwared
    3
    25
    13.4550
    Seth Trade Mwared Tas Moh Moh
    4
    26
    12.8275
    Tina Moh Mwared Trade Tas Moh
    1


    The names in row 2 must be in alphabetical order.
    Last edited by shg; 07-18-2015 at 02:56 PM. Reason: Better layout
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    Thanks everybody
    I have attached my solution in post 2
    I created another sheet .. copy all the data and sort according to Marks Column
    Then used some formulas as illustrated in sheet1 till I could achieve my results in Column R

    After that I used a simple formula to look for the name and return the final result

    So simply I need to summarize all these steps to be executed in code once without the aid of creating helper sheet or even create it temporarily and at the end to be deleted ...
    Hope it is clear now

    @shg
    Is it necessary : The names in row 2 must be in alphabetical order ???
    Thanks for help
    I will give it a try in the original file

  6. #6
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Populate each item to proper place


    Hi,

    These are the steps according to my logic :

    **********************************************************************
    "The distribution would be according to the highest marks"
    So the data is sorted descending by column J (Marks)

    This is the result :

    EF1094403A.GIF

    **********************************************************************
    Process first column (Wish I) :

    Available slots are :
    Moh : 7
    Mwared : 6
    Tas : 5
    Trade : 2

    EF1094403B.GIF

    For fdge, jth1-jth6, they all got the desired Wish, that is Moh

    But starting form jth7, all available slots for Moh has beed used up, so they (jth7-jth14,jth17) must proceed to next Wish

    For jth15 and jth18, they wish Tas, and still available, so they got it.

    For jth16, he wishes Mwared, and still available, so he got it.

    So now, available slots are :
    Moh : 7 - 7 = 0
    Mwared : 6 - 1 = 5
    Tas : 5 - 2 = 3
    Trade : 2

    **********************************************************************
    Process second column (Wish 2) :

    Available slots are :
    Mwared : 5
    Tas : 3
    Trade : 2

    EF1094403C.GIF

    For jth7-jth10,jth12, they all got the desired Wish, that is Mwared

    But for jth14 and jth17, all available slots for Mwaredhas beed used up, so they must proceed to next Wish

    For jth11 and jth13, they wish Tas, and still available, so they got it.

    For the last person (in Arabic letter), he wishes Trade, and still available, so he got it.

    So now, available slots are :
    Mwared : 5 - 5 = 0
    Tas : 3 - 2 = 1
    Trade : 2 - 1 = 1

    **********************************************************************
    Process third column (Wish 3) :

    EF1094403D.GIF

    Available slots are :
    Tas : 1
    Trade : 1

    For jth14, he wishes Tas, and still available, so he got it.

    But for jth17, all available slots for Tas has been used up, so he must proceed to next Wish

    So now, available slots are :
    Tas : 1 - 1 = 0
    Trade : 1

    **********************************************************************
    Process fourth column (Wish 4) :

    Available slots are :
    Trade : 1

    EF1094403E.GIF

    jth17 got Trade

    **********************************************************************

    If the above steps are the expected, then the code is :

    Please Login or Register  to view this content.
    Usage :
    Select K8:K27 and enter this array formula (ended with Ctrl Shift Enter) :
    Formula: copy to clipboard
    Please Login or Register  to view this content.




    Regards

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    Thank you very very much mr. Karedog for this great effort

    I tested the udf and found the output is not correct for mine ...
    The logic is that Marks are the first criteria so the person who got the highest mark is the first person to apply his wish (he has the prioprity)

    Look at row 19 after applying the udf : you will find that this person has 15.27 so he has the priority of first wish
    The udf fucntion gave me "Tas" while he is worth "Moh"
    Generally please look at the results in sheet1 column R in post 2 attachment to see the final and correct results

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    Mr. Karedog
    I get confused....I revised my attachment and found that in sheet1 I put wrong formulas .. I correct the formulas to get the desired results
    Now the desired results are in sheets("Final") in column O
    But the results are different from your UDF results

    Please look at this attachment to see the idea again. May be I'm wrong
    Attached Files Attached Files

  9. #9
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Populate each item to proper place

    Ah, sorry, I forgot to sort back the output array back to original data layout, here it is :

    Please Login or Register  to view this content.
    About your calculation, please look at sheet1 row 9 :
    jth7, he has these wishes :
    Moh | Mwared |Trade |Tas
    all the Moh's has been booked row 2 to 8 (fdge, jth1-jth6), so he can't get first wish (Moh), so he can get the second wish (Mwared)
    But why from your calculation he got Trade (third wish) while he has a high rank mark, so he can get the second wish (Mwared) instead ?

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    I didn't test the last modification yet ...
    As for your comment :
    If you look at the attachment in post 8 you will find the correct results as you state
    So jth7 can get the second wish ...
    As for your questions : the wishes are input data for each person ..they represent their wishes (may has high mark but he wishes any section)
    Hope it is clear
    I will test your post 9 and come back again

  11. #11
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Populate each item to proper place

    Please look at Sheet1 :

    at row 18, from your calculation jth16 got Moh, but this is exceeding available slot for Moh (7 slots). Total Moh in this sheet is 8.
    at row 15, from your calculation jth13 got Mwared (Wish3), but actually he can got Tas (Wish2)

    By correcting these two, all the order will be changed.

    BTW, how do you find my explanation in Post #6, is the logic as you expected ?

  12. #12
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    Mr. Karedog
    It seems that I'm very confused of results
    Actually your logic is correct ...
    Look at Sheet1 at Column AB I put my notes manually after taking your results and copy and paste as values and re-sort the range according to Marks Column
    Look at Column("AB")

    Thanks for your great effort
    Attached Files Attached Files
    Last edited by YasserKhalil; 07-18-2015 at 06:03 PM.

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Populate each item to proper place

    I will give it a try in the original file
    The workbook is posted at https://app.box.com/s/rfeplgz9tsgkji06rxt61tqd4gb5la3b

  14. #14
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Populate each item to proper place

    Ok, I think I got it, you want to execute row by row, not column by column.
    This code will give the same result as your file in #12.

    Please Login or Register  to view this content.

    Regards

  15. #15
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    @Shg
    Thank you very much for this great solution ...
    It's very well except for one important thing : you neglected in your file column B titled (Score)
    It's very important and must be put in mind

    As an idea ... what about sorting column Marks then apply shg solution .. Will it help to solve this complicated issue?

  16. #16
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    Mr. Karedog
    Thank you very very much for solving this complicated issue
    Now it is very very good and excellent solution

    THANK YOU FROM NOW TILL I SURVIVE
    Last edited by YasserKhalil; 07-19-2015 at 05:49 AM.

  17. #17
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Populate each item to proper place

    you neglected in your file column B titled (Score)
    It was not neglected; the formula assumes that your data is sorted by score, as it was in the example.

    Let that not diminish Allah's beneficence upon karedog.

  18. #18
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    @shg
    Is it possible to sort the data by formulas?
    Thanks for great help
    I liked your solution alot but it is not my complete need.
    Can it be possible to create another sheet and by formulas sort the data then we can get our desired results without VBA code in that case?

    @Karedog
    How can I follow the steps of UDF function by pressing F8 to watch how it works?
    Last edited by YasserKhalil; 07-19-2015 at 05:59 AM.

  19. #19
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    Mr. Karedog
    I'm so sorry for bothering you again
    I have attached the original strucuture of the file as I couln't get the udf function well
    Now I have seven wishes not only four
    There are some comments in row 24 about Wishes columns and Marks column ..
    The range of the second parameter is range("C11:D17")

    Thanks advanced for help
    Attached Files Attached Files

  20. #20
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Populate each item to proper place

    @Yasser:
    You are welcome, glad I can help.

    To perform step by step debugging for UDF, you can read from this link :
    http://www.listendata.com/2014/05/ex...r-defined.html

    But since this UDF use "Application.Caller" statement, we cannot directly call the UDF from the sub like in that link.
    Rather, in the caller sub, we set the formula of a cell to this UDF.
    Please add this code, put cursor in the "Sub Tracer()" line, and press F8 to start debugging.

    Please Login or Register  to view this content.
    -----------------------
    About the file in post #19, your "Wish table" layout is changed (from 2 columns to 4 columns), so the code need a little adjustment.
    Add the code marked with red line below, to existing code :
    Please Login or Register  to view this content.
    @shg:
    Amen, I desperately need such thing right now


    Regards

  21. #21
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    Thanks a lot Mr. karedog
    I tried your modification but I got Value error in the output range ...
    Note that the wishes are not just four, it is seven wishes in the file Columns("H:N")

  22. #22
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Populate each item to proper place

    Please try this file.
    Attached Files Attached Files

  23. #23
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    Thanks a lot for this great and very helpful UDF function
    It's a wonderful gift
    And it needs about a month to study the great lines of code to learn from you

  24. #24
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Populate each item to proper place

    You are welcome.
    No, I don't think so, I guess 28 days will be enough


    Regards

  25. #25
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    Just a little question:
    Is there a reference in the udf function to the number of Wish columns? and the Marks Column?
    If possible I need to refer to the Marks Column in the formula
    eg
    =wish(E25:Y378,A11:D17,H:N,Y:Y)
    If this modification will take long time, don't care about me ..

    I will try to study it in 27 days (I will work hard to achieve that)

  26. #26
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Populate each item to proper place

    Please Login or Register  to view this content.

    Usage :
    Function Wish(rngData As Range, rngWish As Range, Start_WishColumn As Long, End_WishColumn, MarkColumn As Long)
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    PHP Code: 
    rngData          E25:Y378
    rngWish          
    A11:D17
    Start_WishColumn 
    4  (fourth column of rngData)
    End_WishColumn   10 (tenth column of rngData)
    MarkColumn       21 (21st column of rngData

    Now, since you have mentioned that you will work very hard for it, I am positive that you can achieve it in 26.3333 days.


    Regards

  27. #27
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    Believe me saying thank you is not enough at all
    I need more words to thank you for this great and magic solutions

    But what a pity .. I'm just obliged to say only : thank you very much and god bless you

  28. #28
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Populate each item to proper place

    You are welcome. Actually, I need a lot of blessing at this time period of my life.


    Regards

  29. #29
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    Mr. Karedog
    I'm sure you will hate me because of many requests>>
    Can you add to the code .. if the person has mark less that specific mark say 10 , if the person has a mark < 10 then in the result should appear the word "Without" ...?

  30. #30
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Populate each item to proper place

    Not to worry, I still have about 500 posts to after, afterall

    Please Login or Register  to view this content.
    Usage :
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  31. #31
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Populate each item to proper place

    Perfect perfect perfect
    you are perfect and awesome ..
    I feel that I am in a dream .. really I feel that
    I can't imagine that I achieved all my goals today

    Till we meet again in another issue I have to say good night and goodbye

  32. #32
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Populate each item to proper place

    You are welcome, glad I can help.


    Regards

+ 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] Put value in its proper place
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-19-2014, 12:13 PM
  2. Need Help with how to populate using the proper formula
    By nexgensupps in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-09-2014, 07:18 PM
  3. Replies: 9
    Last Post: 11-24-2013, 08:30 AM
  4. Replies: 1
    Last Post: 11-26-2012, 09:17 AM
  5. How to make a graph start at the proper place?
    By Adrian20XX in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 06-10-2009, 05:55 AM
  6. Replies: 1
    Last Post: 10-01-2007, 07:46 PM
  7. [SOLVED] Is this the proper place to ask my question?
    By amkazen in forum Excel General
    Replies: 1
    Last Post: 03-01-2006, 01:25 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