+ Reply to Thread
Results 1 to 22 of 22

Group sort candidates

  1. #1
    Forum Contributor
    Join Date
    04-19-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    180

    Group sort candidates

    Hi

    I have a list of candidates with some data which I need to sort into 4 groups using VBA. The number of candidates can change so the group tab needs to be able to "extend" itself.

    The candidate data (tab 2) itself is displayed in 2 parts (Columns B to D and Columns H to J). Ideally, once grouped, I need to distinguish between these 2 sets of groups. At the moment I have just used two colours (Orange Group and Blue Group).

    I have attached my DUMMY DATA sheet and on the first tab I have shown part of how the end result should look like.

    Can anyone help?

    Many thanks in advance.
    Attached Files Attached Files
    Last edited by technik; 05-26-2020 at 12:04 PM.

  2. #2
    Forum Contributor
    Join Date
    04-19-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Group sort candidates

    I have made some progress with this however not quite there yet. Was hoping someone could take a look and help please? Uploaded my file again.
    Attached Files Attached Files
    Last edited by technik; 05-31-2020 at 03:53 PM.

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Group sort candidates

    From what I remember I spent many hours on the first sample and not able to spend that kind of time on this at the moment.

    You should be able to copy and paste the ranges such as this will copy the contents of the candidates cell and paste it into the groups cell
    Please Login or Register  to view this content.
    Just a test, loop through your orange group and copy the pictures into groups sheet

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    04-19-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Group sort candidates

    Hi Dave

    Thanks for your post and I appreciate your time and help.

    The specific difficulty in coding I am having is :

    1.checking which group number the candidate(s) in the Orange group AND Blue Group belong to (by looking at the data worksheet).
    2. If belong to Group 1 then (only) copy those photo(s) and associated data to the 'groups' tab in the 'Group 1' section

    If I can get that working then I can just re-create that for the other groups (of all 4 groups cannot be done in one macro)

    I'd really appreciate it if you could look at my updated sheet and I think you will have a better idea of what I mean. This issue is not at all as time consuming as the previous issue as I think it's just looping through to check and copy/paste and not dealing with lots of named ranges.

    Really appreciate it - many thanks.
    Attached Files Attached Files
    Last edited by technik; 06-02-2020 at 05:30 PM.

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Group sort candidates

    The key would be the admin numbers.

    Get the admin numbers from the data sheet and put them in the groups sheet, then from there you can get the admin numbers to find the
    correct picture to copy.

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

  6. #6
    Forum Contributor
    Join Date
    04-19-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Group sort candidates

    Hi Dave.

    Thanks - that's a great help.

    In the second macro could you please explain what
    Please Login or Register  to view this content.
    is doing? When I try running this on my master sheet it says "no cells were found" with the line below highlighted
    Please Login or Register  to view this content.
    I'm assuming this is where it is searching for the admin number?

    The range on worksheet2 is the same as on my master sheet however worksheet1 (candidates tab) obviously has more/less candidates so not sure this is an issue?

    Many thanks once again
    Last edited by technik; 06-03-2020 at 09:41 AM.

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Group sort candidates

    SpecialCells(xlCellTypeConstants, 1)

    This is just a short way of making just numbered cells the range, or the loop will end up going through ever cell in the columns.

    Your sample uses admin numbers, actual numbers that's why I went this way, if the admin # are not actual numbers, you can change that 1 to a 23.

    "No cells were found" is not the find line it is the specialcells that can't find numbers.
    Last edited by davesexcel; 06-03-2020 at 11:01 AM.

  8. #8
    Forum Contributor
    Join Date
    04-19-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Group sort candidates

    Thanks Dave.

    A bit confused as the admin numbers ARE numbers (that are listed using a VLOOKUP). They are there on the 1st candidates tab. Obviously on the 2nd 'groups' tab all the candidate data/info needs to populate itself via the macro.

    I've attached my test sheet - can't see why I am still getting the error as everything is identical ... I think ???????????????
    Attached Files Attached Files
    Last edited by technik; 06-03-2020 at 09:29 PM.

  9. #9
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Group sort candidates

    The Groups in the group column in Data sheet are not the same groups in code Group1 <>Group 1
    You are over writing the Admin # with the name

    -
    2020-06-03_19-35-36.jpg

  10. #10
    Forum Contributor
    Join Date
    04-19-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Group sort candidates

    Thanks Dave - have corrected that now.

    The code does seem to run but I need to check two things:

    1. If there are no candidates in a particular group, the code will just not display any data for that section?
    2. If you have a look at my attached sheet, there are 41 candidates in the orange+blue group (tab1) although there are 60 candidates altogether (see data tab). Now in the 'groups' worksheet (tab2) there should only be 41 candidates as this worksheet is only meant to show the candidates in the orange+blue groups. At the moment all 60 candidates are being shown in the 'groups' worksheet and that is not the idea. Sorry if this was not clear in post#4.
    Attached Files Attached Files

  11. #11
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Group sort candidates

    Try it now,
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    04-19-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Group sort candidates

    Thanks Dave.

    Everything looks fine but bizarrely getting an error on the second macro. Can't work out where the issue is as everything looks ok.

    Very strange as can't see what is missing and what it is not liking. One thing I notice was that upon running the code the 1st time, (I am sure) the group were correctly ordered. When I closed the sheet down and the ran the code again, that's when I get the error. So I think something gets deleted between the runs and that's why I get the error??
    Attached Files Attached Files
    Last edited by technik; 06-05-2020 at 06:34 PM.

  13. #13
    Forum Contributor
    Join Date
    04-19-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Group sort candidates

    Forgot to mention that the "xlCellTypeConstants" is showing as =2 when I hover over it. Don't think this is correct?

  14. #14
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Group sort candidates

    You need the lookin:=xlvalues, didn't see required this morning.


    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    04-19-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Group sort candidates

    Sorry Dave where would I add/amend this code?

    Here is the 1st and 2nd macro at the moment
    Please Login or Register  to view this content.
    Last edited by technik; 06-05-2020 at 09:49 PM.

  16. #16
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Group sort candidates

    In the Firstmacro, you need to have it in 4 lines.
    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    04-19-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Group sort candidates

    Thanks Dave - will try it.

    And thank you for your patience with me!

  18. #18
    Forum Contributor
    Join Date
    04-19-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Group sort candidates

    Hi Dave

    The code generally runs ok however I have come across one issue. When copying admin numbers across from my master sheet, I keep getting the same error as above and the picture(s) also does not load. If I remove any trailing zeros (e.g change 000812 to 812) from all admin numbers, I no longer get the error. Problem is I need the exact admin number as it is (as I am using those exact admin numbers to loads the pics on the 1st candidates ws).

    Why would trailing zeros cause an issue?
    Last edited by technik; 06-06-2020 at 12:18 PM.

  19. #19
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Group sort candidates

    How are the leading zeros being entered on the worksheet?

  20. #20
    Forum Contributor
    Join Date
    04-19-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Group sort candidates

    The numbers themselves are just being copied from another sheet .. right-click ... paste as Values onto my master sheet.

    I have tried 'formatting' the numbers as 'General', 'Number', 'Text' to no avail. Maybe the issue is in the actual pasting of the numbers I am not sure.

    I have both working and non-working versions so you can see the error in action.

    Thanks again

  21. #21
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Group sort candidates

    Refer to post #7

  22. #22
    Forum Contributor
    Join Date
    04-19-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Group sort candidates

    Thanks Dave - and thanks again for all your help.

+ 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. sort then insert entire row then sort again by group
    By k1dr0ck in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-26-2018, 09:16 PM
  2. sort by group and total by each group
    By mheinemann in forum Excel General
    Replies: 3
    Last Post: 04-30-2015, 11:48 AM
  3. Replies: 1
    Last Post: 04-18-2014, 05:54 PM
  4. Replies: 1
    Last Post: 10-19-2012, 07:55 AM
  5. Sort a group of names based on the group total
    By ron2k_1 in forum Excel General
    Replies: 3
    Last Post: 08-13-2010, 01:16 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