Results 1 to 14 of 14

Thread: Sort Arrange Move Rows

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Sort Arrange Move Rows

    Is it possible to move entire rows (A:I at least) up or down based on either date cell or a status cell (If Statement).
    I don't know if I explained that very well.
    I have a Toggle Button that Toggles between Edit state and Operational State.
    Edit state: I edit everything not worrying about sorting the dates Sequentially.
    Operational State triggers the Macro that sorts the Rows based on the Date nearest date being Row1, then Row2 Etc Etc. Leapfrog? ;-) Man it's Hard Work being Lazy..

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: Sort Arrange Move Rows

    Say I put a bunch of Dates in a Column Randomly. Would this maybe work to arrange them in descending order? When it inserts the cell it should shift cells down.

    Code:
     Sub ProjSort()
    
        Dim dCell As Range
    
            For Each dCell In Sheets("LD").Range("B6:B82")
            If dCell.Offset(1, 0) <> "" Then
            Select Case DateDiff("d", Date, dCell.Value)
                
    '            Case Is < dCell:   ??  'Cut and Paste to dCell.Offset(2, 0)
    
            End Select
            End If
          
    
        Next
    End Sub
    Last edited by tome10; Nov 11th, 2009 at 09:28 PM.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Sort Arrange Move Rows

    why not just sort the entire range by whichever column

    try recording a macro
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: Sort Arrange Move Rows

    I made this.. It doesn't error, but it isn't doing anything either..

    Code:
     Sub ProjSort()
    
        Dim dCell As Range
    
            For Each dCell In Sheets("LD").Range("B6:B82")
            If dCell.Offset(1, 0) <> "" Then
            Select Case DateDiff("d", Date, dCell.Value)
                
                Case Is > dCell:    Range(dCell.Offset(1, 0)).Select
                        Application.CutCopyMode = xlCut
                        Range(dCell.Offset(2, 0)).Select
                        Selection.Insert Shift:=xlDown
                        Application.CutCopyMode = False
            End Select
            End If
          
        Next
        
    End Sub

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Sort Arrange Move Rows

    i have not tested the code you are using, but it seems to compare the datediff with itself, as numberofdays compare to date, so is unlikley to do what you expect
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: Sort Arrange Move Rows

    Hmm. Date Diff is comparing the Dcell with the Date. Not the date of Dcell and Dcell offset.

    Code:
     Sub ProjSort()
    
        Dim dCell As Range
    
            For Each dCell In Sheets("LD").Range("B6:B82")
            If dCell.Offset(1, 0) <> "" Then
            
            Select Case DateDiff("d", Date, dCell.Offset(1, 0)).Value ' It errors here. No Object.
                Case Is < dCell:    Range(dCell.Offset(1, 0)).Select
                        Application.CutCopyMode = xlCut
                        Range(dCell).Select
                        Selection.Insert Shift:=xlDown
                        Application.CutCopyMode = False
            End Select
            End If
          
        Next
        
    End Sub
    Last edited by tome10; Nov 12th, 2009 at 05:47 PM.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: Sort Arrange Move Rows

    Hoabout this?

    Code:
        Private Sub ProjSort()
            
            Dim dCell As Range
            For Each dCell In Sheets("LD").Range("B6:B82")
            If dCell.Offset(1, 0) <> "" And dCell.Offset(1, 0) < dCell Then
                Range(dCell.Offset(1, 0)).Select  'errors here Global Fails
                        Application.CutCopyMode = xlCut
                        Range(dCell).Select
                        Selection.Insert Shift:=xlDown
                        Application.CutCopyMode = False
                
            End If
            
            Next
            
        End Sub
    Last edited by tome10; Nov 12th, 2009 at 08:54 PM.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: Sort Arrange Move Rows

    I found this. Anyone know how to use it?

    Code:
    DateValue()
    Date part of argument (excellent for ordering by date)
    Example: SELECT * from tblPeople ORDER BY DateValue(Review)

    Nevermind apparently it's a Function.
    Last edited by tome10; Nov 12th, 2009 at 09:06 PM.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: Sort Arrange Move Rows

    This is working somewhat.. I need it to shift cells down when it inserts. ??

    Code:
        Sub ProjSort()
            Dim rng As Range
            'Dim intRow As Integer, intCol As Integer
            For Each rng In Sheets("LD").Range("B6:B82")
            If Not IsEmpty(rng) Then
                If DateValue(rng.Value) > rng.Offset(1, 0) Then
                    rng.Offset(1, 0).Cut Destination:=rng
                    Selection.Insert Shift:=xlDown
                    Application.CutCopyMode = False
             End If
          End If
       Next rng
    End Sub

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: Sort Arrange Move Rows

    I found it. Too simple.. I didn't realize Excel had a built in Sort. Never used it.

    Code:
        Range("A6:I82").Sort Key1:=Range("B6"), Order1:=xlAscending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Sort Arrange Move Rows

    i suggested that in post #3
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: Sort Arrange Move Rows

    haha.. That's what I thought I was doing... I was Recording a macro of me (Manually) sorting the rows by the date column. I didn't know the Data-Sort command was there. ;-)

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: Sort Arrange Move Rows

    Pete, How do I make this only fill in the link only if RC[4] has someting there?

    Code:
            For i = 6 To 82
    
            With Cells(i, 1)
            .FormulaR1C1 = "=HYPERLINK(""http://eic.mycom.com/eic_drw/qr/"" &RC[4],RC[4])"
            With .Font
            .Bold = True
            .Name = "Arial"
            .Size = 12
            .Underline = xlUnderlineStyleSingle
            .ColorIndex = 5
            End With
            End With
            Next

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: Sort Arrange Move Rows


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width