+ Reply to Thread
Results 1 to 20 of 20

Sort rows by equation

  1. #1
    Registered User
    Join Date
    04-23-2013
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Sort rows by equation

    Hello to all,
    I would like to set macro which will be called using button. What macro actually has to do is to sort all rows by this order:
    1. To recognize which of the rows in the table has the Center-X.Value=1 and Center-Y.Value=0 and to move entire row in the nested position below first row (header titles)
    2. To sort all other rows by equation: StartPoint-X(i).Value=EndPoint-X(i-1)
    Note: "StartPoint-X" & "EndPoint-X" are just names in header row

    I have created some code in the attached workbook but I have to modify it.
    Also, there are two images which show table before and after sorting. This is done manually just to show what I would like to do.
    I would appreciate if someone could help me.
    This is unsorted table.
    unsorted.PNG
    This is sorted table.
    sorted.PNG

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

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

    Re: Sort rows by equation

    Maybe :
    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Registered User
    Join Date
    04-23-2013
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Sort rows by equation

    Hello,

    These days I have tested and it works perfect. The only thing that I would like to change is to modify it little bit cause it works only if there is no a gap (empty row) between the rows. If there is a gap, it doesn't work.
    Last edited by jeffreybrown; 02-28-2017 at 08:36 AM. Reason: As per Forum Rule #12, please don't quote whole post unless necessary -- it's just clutter.

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

    Re: Sort rows by equation

    Just change the input range as below :
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-23-2013
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Sort rows by equation

    Thank you! It works perfect! Very appreciate your help!

  6. #6
    Registered User
    Join Date
    04-23-2013
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Sort rows by equation

    I missed something . The values that I am trying to arrange are coordinates of some sketch items from AutoCAD. Sometimes, during a export from the AutoCAD, coordinates of StartPoint and EndPoint of the lines (Lines can be recognized by CenterPoint -X=0 and CenterPoint-Y=0) are switched so I have to do it manually as on the video. It would be the best if macro recognize is there a comparing value in the column A, if there is not, then search in the column C and when you found it then switch cells, StartPoint coordinates go on the places of the EndPoint and opposite (EndPoint coordinates go on the places of the StartPoint).
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    04-23-2013
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Sort rows by equation

    I had a problem to update the video. Sorry.
    https://youtu.be/kh-R4pSThvo

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

    Re: Sort rows by equation

    I will assume that first starting point is the row which both Center-X and Center-Y is 0 (not 1 and 0 like in your first attached file).
    In the example attached, I switched some StartPoint and EndPoint nodes to mimic your request.

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

  9. #9
    Registered User
    Join Date
    04-23-2013
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Sort rows by equation

    Quote Originally Posted by karedog View Post
    I will assume that first starting point is the row which both Center-X and Center-Y is 0 (not 1 and 0 like in your first attached file).
    In the example attached, I switched some StartPoint and EndPoint nodes to mimic your request.

    Please Login or Register  to view this content.
    Hello karedog,
    The previous code that you wrote works PERFECT, with one simple modification that I am trying to do. Problem happens when program can't find the same value in the column A.
    Actually the value is in the column C and cells must change places. A(i)goes to C(i) and C(i) goes to A(i). The same is for other two cells B(i) and D(i).
    So if program during a loop can't find a value in the column A, then search in the column C and when program found the value in the column C then send C.value & D.value on the place of A.value and B.value, and opposite.
    https://youtu.be/D-u3huNmCHo
    Attached Images Attached Images

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

    Re: Sort rows by equation

    Yes, that is what exactly I do in the code on post #8. Did you test the attached file ? In that file, I make some StartPoint and EndPoint nodes are "switched" (marking by red cell).

  11. #11
    Registered User
    Join Date
    04-23-2013
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Sort rows by equation

    Quote Originally Posted by karedog View Post
    I will assume that first starting point is the row which both Center-X and Center-Y is 0 (not 1 and 0 like in your first attached file).
    In the example attached, I switched some StartPoint and EndPoint nodes to mimic your request.
    The first starting point is row with Center-X<>0 and Center-Y=0.
    When I started the topic, I have set to be Center-X=1 and Center-Y=0 to simplify the problem and I have used integer numbers for easy comparison between two cells.

    I have changed just this row in your first code and it works fine.
    Please Login or Register  to view this content.

    is changed to:
    Please Login or Register  to view this content.

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

    Re: Sort rows by equation

    Quote Originally Posted by blueye89 View Post
    The first starting point is row with Center-X<>0 and Center-Y=0.
    This information is never mentioned before, so is the "non continous" range.

    However, you can spot where the line to fix this.

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

  13. #13
    Registered User
    Join Date
    04-23-2013
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Sort rows by equation

    Quote Originally Posted by karedog View Post
    This information is never mentioned before, so is the "non continous" range.

    However, you can spot where the line to fix this.

    So, if that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    Capture2.PNG

    I don't worry about the starting row. Program recognize the starting row exactly as I wanted.
    Attached Files Attached Files

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

    Re: Sort rows by equation

    You must unmerge G8:M8 first, then run this sub :

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    04-23-2013
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Sort rows by equation

    Quote Originally Posted by karedog View Post
    You must unmerge G8:M8 first, then run this sub :

    Please Login or Register  to view this content.
    Hi @karedog
    That's what I was trying to do. Thank you very much.
    SOLVED!

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

    Re: Sort rows by equation

    You are welcome, glad I can help.

    Regards

  17. #17
    Registered User
    Join Date
    04-23-2013
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Sort rows by equation

    Quote Originally Posted by karedog View Post
    You are welcome, glad I can help.

    Regards
    Hello karedog,
    I would like to say thank you again cause code bellow that you wrote works perfect.
    Please Login or Register  to view this content.
    I would like just to know, is it possible to catch the moment where in the row, StartPoint and EndPoint are switched positions?
    In other words, to add new string value in the column "G" and row (i).
    Please Login or Register  to view this content.
    If StartPoint and EndPoint are switched positions
    or
    Please Login or Register  to view this content.
    if StarPoint and EndPoint are not switched positions.

    It is very important to catch the switch change for my CAD application.
    img16.PNG

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

    Re: Sort rows by equation

    Should be :
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    04-23-2013
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Sort rows by equation

    Quote Originally Posted by karedog View Post
    Should be :
    Please Login or Register  to view this content.
    Perfect!
    Thank you!

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

    Re: Sort rows by equation

    You are welcome.

    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. Sort Rows and copy sort results to new worksheet?
    By Apache_sim in forum Excel General
    Replies: 0
    Last Post: 06-30-2015, 03:17 AM
  2. Need macro that hides rows based on the result of an equation.
    By fletch77776 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-12-2014, 10:54 PM
  3. [SOLVED] I have a sort macro. How to add script to preselect rows to sort based on column value?
    By Jasonhouse in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-09-2014, 02:25 AM
  4. Replies: 3
    Last Post: 03-06-2011, 01:38 PM
  5. Replies: 4
    Last Post: 08-12-2010, 09:56 AM
  6. Filling in equation for several rows
    By grey_fox33 in forum Excel General
    Replies: 1
    Last Post: 06-22-2010, 08:50 PM
  7. sort alphabetically and numerically, then sort rows
    By luke20allen in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-01-2008, 07:00 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