help: This macro deletes #'s it isn't supposed to

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
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
What are you actually trying to delete?

Could you post a larger example?

And also a before and after showing what you want.
 
Upvote 0
Here is part of the original The 5 And the A are thrown into seperate columns by a formula

GD10A-P-741-2 5A 5 A
GD10A-P-741-2 5B 5 B
GD10A-P-741-2 6 6
GD10A-P-741-2 7A 7 A
GD10A-P-741-2 8B 8 B
GD10A-P-741-2 8C 8 C
XX10Z-O-745-9 5 5
XX10Z-O-745-9 6 6
XX10Z-O-745-9 7 7
XX10Z-O-745-9 7 7




After my first macro it will end up as

GD10A-P-741-2 5B 5 B
GD10A-P-741-2 6 6
GD10A-P-741-2 7A 7 A
GD10A-P-741-2 8C 8 C
XX10Z-O-745-9 5 5
XX10Z-O-745-9 6 6
XX10Z-O-745-9 7 7
XX10Z-O-745-9 7 7



But now after THIS one I Get

GD10A-P-741-2 5B 5 B
GD10A-P-741-2 7A 7 A
GD10A-P-741-2 8C 8 C
XX10Z-O-745-9 7 7


But I want
GD10A-P-741-2 5B 5 B
GD10A-P-741-2 6 6
GD10A-P-741-2 7A 7 A
GD10A-P-741-2 8C 8 C
XX10Z-O-745-9 7 7
 
Upvote 0

Forum statistics

Threads
1,222,441
Messages
6,166,049
Members
452,009
Latest member
oishi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top