+ Reply to Thread
Results 1 to 18 of 18

VBA Sorting Nth Range not working

  1. #1
    Registered User
    Join Date
    01-15-2006
    Posts
    46

    VBA Sorting Nth Range not working

    I have a values in column C of stuff1, stuff2 and on down.

    I have a value in cell A1.

    I want to start in C1, and every Nth, where N is the value in cell A1, select and paste into column H.

    My problem is that the selected cells don't start in C1, in fact, based on the value in A1, it starts in different cells in column C. AND, if i press the button twice, the returned values are different.

    Please Login or Register  to view this content.
    Link to source code
    i've attached a sample.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: VBA Sorting Nth Range not working

    Hi

    The code runs fine for me.
    I would amend it slightly to switch off screen updating, and to clear the contents of column J before copying the new data range to J1.
    Amended code shown below
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 05-16-2009 at 05:43 PM. Reason: Added Code Tags
    --
    Regards
    Roger Govier
    Microsoft Excel MVP

  3. #3
    Registered User
    Join Date
    01-15-2006
    Posts
    46

    Re: VBA Sorting Nth Range not working

    Thanks Roger,

    I'm still getting the same results:

    i.e.

    A1= 1 works
    A1= 2 starts at "stuff99" and every 2 on down
    A1= 3 starts at "stuff79" and every 3 on down
    A1= 4 starts at "stuff53" and every 4 on down
    A1= 5 starts at "stuff31" and every 5 on down
    A1= 6 starts at "stuff7" and every 6 on down
    A1= 7 works

    A1= 8 and more, the code works fine for me. I've yet to try it on another machine, but i must use this code on this machine, so i have to figure this out.

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

    Re: VBA Sorting Nth Range not working

    Roger,

    Please edit your post to add code tags.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    01-15-2006
    Posts
    46

    Re: VBA Sorting Nth Range not working

    the final result, is that i want to have the value in A1 be the # of personnel reporting, and divy up the part to be made based on that value into each persons list of work, so i have to start with C1 as the first part to be made, not part 99 or 73 etc.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: VBA Sorting Nth Range not working

    Hello Beechum1,

    This macro has been added to the attached workbook.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Registered User
    Join Date
    01-15-2006
    Posts
    46

    Re: VBA Sorting Nth Range not working

    Thanks Leith. perfect.

    Next question. Since i'm going to be copying every Nth starting in C1 for person 1, and i'm going to be copying every Nth starting in C2 for person 2,
    • should i use another button for person 2
    • should i reset the variables after the "next cell" with a valkill and reassign for person 2
    • should i create new variables for person two, and simply repeat the programming appropriately

    Thanks in advance for all your help, this is as complicated as i've gotten with programming, and I LOVE it.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: VBA Sorting Nth Range not working

    Hello Beechum1,

    Will the data for person 2 be copied into column "J" also or to another column?

  9. #9
    Registered User
    Join Date
    01-15-2006
    Posts
    46

    Re: VBA Sorting Nth Range not working

    ColumnK.

    This is what i have so far.

    Please Login or Register  to view this content.
    What i think i need to do, is assign each "person" to a "sub."

    So, i'll do something like:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Now, what it appears i need next is an if then statement, but there should be a more elegant solution to this. I'm going to call only Person_1 if the value in A1 is 1. I'm going to call Person_1 and Person_2 if the value in A1 is 2.

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: VBA Sorting Nth Range not working

    Hello Beechum1,

    The same macro can be used for all persons. It just requires some slight changes. How many persons will there be?

  11. #11
    Registered User
    Join Date
    01-15-2006
    Posts
    46

    Re: VBA Sorting Nth Range not working

    So this is what i have figured out so far, but i need to assign some "ifs" based on the value in A1...

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    01-15-2006
    Posts
    46

    Re: VBA Sorting Nth Range not working

    I found this Here


    Please Login or Register  to view this content.
    But i can't figure out how this applies to what i'm doing exactly. I'm sure that i'll have to change the Case statements to:

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    01-15-2006
    Posts
    46

    Re: VBA Sorting Nth Range not working

    Quote Originally Posted by Leith Ross View Post
    Hello Beechum1,

    The same macro can be used for all persons. It just requires some slight changes. How many persons will there be?
    up to 10, but variable daily.


    and to be clear, my trigger is CommandButton1_Click

  14. #14
    Registered User
    Join Date
    01-15-2006
    Posts
    46

    Re: VBA Sorting Nth Range not working

    Seems like i found it.

    Please Login or Register  to view this content.
    And so on for up to 10 people. Does that look about right?
    Attached Files Attached Files
    Last edited by beechum1; 05-16-2009 at 10:03 PM. Reason: update with attached file

  15. #15
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: VBA Sorting Nth Range not working

    Hello Beechum1,

    You say the number of persons will vary daily. I take it that each person will have a number in column "A", right?

  16. #16
    Registered User
    Join Date
    01-15-2006
    Posts
    46

    Smile Re: VBA Sorting Nth Range not working

    Quote Originally Posted by Leith Ross View Post
    Hello Beechum1,

    You say the number of persons will vary daily. I take it that each person will have a number in column "A", right?
    to be clear, the number of persons will be the value in A1. It appears i've figured it out though, the previous attached file, i've built out to person_6 and appears to work perfectly.

  17. #17
    Registered User
    Join Date
    01-15-2006
    Posts
    46

    Re: VBA Sorting Nth Range not working

    Attached is my current ver.
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    01-15-2006
    Posts
    46

    Re: VBA Sorting Nth Range not working

    next step is to only copy and paste 20 rows in each column. I have fixed space to paste to in my programming area. Seems like a for... next loop, but i haven't figured out the placement, can someone get me started?
    attached above is the most recent testing version of this problem.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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