|
-
Nov 7th, 2009, 12:57 AM
#1
Thread Starter
Hyperactive Member
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..
-
Nov 11th, 2009, 09:20 PM
#2
Thread Starter
Hyperactive Member
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.
-
Nov 11th, 2009, 09:31 PM
#3
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
-
Nov 12th, 2009, 01:39 PM
#4
Thread Starter
Hyperactive Member
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
-
Nov 12th, 2009, 03:08 PM
#5
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
-
Nov 12th, 2009, 05:40 PM
#6
Thread Starter
Hyperactive Member
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.
-
Nov 12th, 2009, 06:32 PM
#7
Thread Starter
Hyperactive Member
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.
-
Nov 12th, 2009, 08:57 PM
#8
Thread Starter
Hyperactive Member
Re: Sort Arrange Move Rows
I found this. Anyone know how to use it?
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.
-
Nov 12th, 2009, 10:12 PM
#9
Thread Starter
Hyperactive Member
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
-
Nov 16th, 2009, 08:19 PM
#10
Thread Starter
Hyperactive Member
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
-
Nov 16th, 2009, 09:30 PM
#11
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
-
Nov 16th, 2009, 10:16 PM
#12
Thread Starter
Hyperactive Member
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. ;-)
-
Nov 16th, 2009, 10:41 PM
#13
Thread Starter
Hyperactive Member
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
-
Nov 21st, 2009, 07:09 PM
#14
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|