+ Reply to Thread
Results 1 to 5 of 5

Sort Data Problem

Hybrid View

d888nc Help sorting it all out 04-25-2007, 11:33 PM
antoka05 Try with this code. I saw you... 04-26-2007, 04:16 AM
d888nc This works perfectly although... 04-26-2007, 04:40 PM
antoka05 The relative reference... 04-27-2007, 04:53 AM
d888nc Again thanks for the... 04-30-2007, 11:42 AM
  1. #1
    Registered User
    Join Date
    10-09-2006
    Posts
    22

    Help sorting it all out

    Hello,

    I’m hoping someone can help me with a sort issue I am having. I have several environments in which I am trying to track taskings for and in doing so I need to print out what is currently going on within all of them. I do have tasking that spawns child tasking which introduces a Parent Child relationship within my spreadsheet. My customers want me to sort this report by environment which is my first field for the sort. Now I need to sort and hopefully group the parent child taskings together. I am using the below sort which as you can see from the spreadsheet below is not grouping my parent child taskings. Can you help me get this data to sort on Environment, Parent ID, and Record ID, enforcing a way to group the Parent ID, and Record ID. Ideally, it would be nice to have the Record ID of the parent tasking first then any subsequent children report after (as it is doing for 2880750).

    Note Parent ID 2880735 which has spawned Record ID 2881806. I am unable to get these Parent Child request to group together.

    Any help would be greatly appreciated.


        Columns("A:J").Select
        Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("E2") _
            , Order2:=xlAscending, Key3:=Range("F2"), Order3:=xlAscending, Header:= _
            xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
            xlSortNormal

    HTML Code: 

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    Try with this code. I saw you have data in column 'A' to 'H' and so I added a column 'I' where I put column 'F' (Parent ID) and column 'E' (Record Id), then sort data for 'Env' and new column 'I' and then delete new added column.

    Sub Macro1()
       lastrow = Cells(Rows.Count, "a").End(xlUp).Row
       Range("i2:i" & lastrow).FormulaR1C1 = "=RC[-3]&RC[-4]"
    
       Columns("I:I").Copy
       Range("i1").PasteSpecial Paste:=xlPasteValues
       Application.CutCopyMode = False
    
       Columns("a:i").Select
       Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, _
          Key2:=Range("I2"), Order2:=xlAscending, _
          Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
          Orientation:=xlTopToBottom, _
          DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
       
       Columns("i").Delete
    
       Range("a1").Select
    End Sub
    I hope it's what you need.

    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    10-09-2006
    Posts
    22
    This works perfectly although I don’t understand line three:

    Range("i2:i" & lastrow).FormulaR1C1 = "=RC[-3]&RC[-4]"
    How can I change this to use the M column as the work space incase I need to add a new column in the future?

    Thank you very much, If you can explain the above line for me I should would appreciate it..

    d888nc

  4. #4
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    The relative reference 'RC[-1]' indicate cell in the same row and in one column on the left (for example, if you are putting formula on column 'M' it references column 'L').

    If you want to put formula on column 'M' with references at column 'H' you need to write 'RC[-5]' because column 'H' is five column on the left of column 'M'.

    Regards,
    Antonio

  5. #5
    Registered User
    Join Date
    10-09-2006
    Posts
    22
    Again thanks for the information; after your explanation and playing around with it I see how it is relative to the position. You all are life savers and I truly appreciate you taking the time to help me learn as I go.

    d888nc

+ 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