shad0w4life
New Member
- Joined
- Nov 4, 2004
- Messages
- 48
Run_Second()
If MsgBox("Performing Filtering Step #2", vbOKCancel) = vbOK Then
Dim rgTest As Range
Dim lgLastRow As Long
Set rgTest = Range("a1").CurrentRegion 'CHANGE START OF RANGE TO SUIT
Let lgLastRow = rgTest.Cells(rgTest.Count).Row
'SORT RANGE
rgTest.Sort key1:=rgTest.Cells(2), order1:=xlAscending, key2:=rgTest.Cells(9), order2:=xlDescending, header:=xlGuess
'DELETE ROWS
Do Until lgLastRow = 2 'CHANGE TO 2 IF RANGE INCLUDES HEADER ROW
If rgTest.Cells(lgLastRow, 2) = rgTest.Cells(lgLastRow - 1, 2) Then
If rgTest.Cells(lgLastRow, 10).Value = "" Then
If rgTest.Cells(lgLastRow, 9) <= rgTest.Cells(lgLastRow - 1, 9) Then
Intersect(rgTest, Rows(lgLastRow)).ClearContents
End If
End If
End If
Let lgLastRow = lgLastRow - 1
Loop
'RESORT RANGE TO REMOVE BLANKS
rgTest.Sort key1:=rgTest.Cells(2), order1:=xlAscending, key2:=rgTest.Cells(10), order2:=xlDescending, header:=xlGuess
Else
End If
End Sub
Here is a sample of what the problem is:
My Spreadsheet starts off looking like this (Row's are like this I cut out N/A stuff)
| 2 | 3 | 9 | 10 |
GD10A-P-741-2 5B 5 B
GD10A-P-741-2 6 6
GD10A-P-741-2 7A 7 A
And after this macro it ends up
GD10A-P-741-2 5B 5 B
GD10A-P-741-2 7A 7 A
But I want it to keep the 6
If MsgBox("Performing Filtering Step #2", vbOKCancel) = vbOK Then
Dim rgTest As Range
Dim lgLastRow As Long
Set rgTest = Range("a1").CurrentRegion 'CHANGE START OF RANGE TO SUIT
Let lgLastRow = rgTest.Cells(rgTest.Count).Row
'SORT RANGE
rgTest.Sort key1:=rgTest.Cells(2), order1:=xlAscending, key2:=rgTest.Cells(9), order2:=xlDescending, header:=xlGuess
'DELETE ROWS
Do Until lgLastRow = 2 'CHANGE TO 2 IF RANGE INCLUDES HEADER ROW
If rgTest.Cells(lgLastRow, 2) = rgTest.Cells(lgLastRow - 1, 2) Then
If rgTest.Cells(lgLastRow, 10).Value = "" Then
If rgTest.Cells(lgLastRow, 9) <= rgTest.Cells(lgLastRow - 1, 9) Then
Intersect(rgTest, Rows(lgLastRow)).ClearContents
End If
End If
End If
Let lgLastRow = lgLastRow - 1
Loop
'RESORT RANGE TO REMOVE BLANKS
rgTest.Sort key1:=rgTest.Cells(2), order1:=xlAscending, key2:=rgTest.Cells(10), order2:=xlDescending, header:=xlGuess
Else
End If
End Sub
Here is a sample of what the problem is:
My Spreadsheet starts off looking like this (Row's are like this I cut out N/A stuff)
| 2 | 3 | 9 | 10 |
GD10A-P-741-2 5B 5 B
GD10A-P-741-2 6 6
GD10A-P-741-2 7A 7 A
And after this macro it ends up
GD10A-P-741-2 5B 5 B
GD10A-P-741-2 7A 7 A
But I want it to keep the 6