Sub test()
Dim rng As Range
Set rng = Worksheets("Sheet1").Range("C1")
Dim x As Integer
x = 0
Do While Not IsEmpty(rng.Offset(x, 0))
If rng.Offset(x, 0) > rng.Offset(x, 1) Then
rng.Offset(x, 0).EntireRow.Delete
Else
x = x + 1
End If
Loop
End Sub
Sub test()
Dim LR As Integer
Dim A As Integer
Dim B As Integer
Range("D1").Select
LR = ActiveCell.CurrentRegion.Rows.Count
B = Selection.Offset(-1, 0)
For A = 1 To LR
If Selection.Value >= B Then
Selection.EntireRow.Delete
Else
Selection.Offset(1, 0).Select
End If
Next A
End Sub
Sub test()
Dim LR As Integer
Dim A As Integer
Dim B As Integer
Range("D1").Select
LR = ActiveCell.CurrentRegion.Rows.Count
B = Selection.Offset(-1, 0)
For A = 1 To LR
If Selection.Value >= B Then
Selection.EntireRow.Delete
Else
Selection.Offset(1, 0).Select
End If
Next A
End Sub
mayuko,Hi,
I need some help with Macro
I want to delete all rows that has values in column D with a value
greater than or equal to C.
Any help would be greatly appreciated! Thank you.
Sub delrows()
Dim col As Range, c As Range, nr&
Dim u(), k&, e, p&
Set col = Range("D:D")
Set c = Cells(1, Columns.Count)
nr = col(Rows.Count).End(3).Row
ReDim u(1 To nr, 1 To 1)
For Each e In col.Resize(nr).Value
k = k + 1
If e >= C Then u(k, 1) = 1: p = p + 1
Next
c.Resize(nr) = u
Cells(1, 1).Resize(nr, Columns.Count).Sort c, 1
Cells(1, 1).Resize(p, Columns.Count).Delete
End Sub
Thank you for guys
Brandon... I ran it, but it didn't do anything on my sheet...
mirabeaumayuko,
Would you like to try this code (on some test data first) and see if it works for youAlthough it occurs to me that your C may not be a numerical value in its own right, as that code assumes, but rather some numerical value(s) located somewhere in column C.Code:Sub delrows() Dim col As Range, c As Range, nr& Dim u(), k&, e, p& Set col = Range("D:D") Set c = Cells(1, Columns.Count) nr = col(Rows.Count).End(3).Row ReDim u(1 To nr, 1 To 1) For Each e In col.Resize(nr).Value k = k + 1 If e >= C Then u(k, 1) = 1: p = p + 1 Next c.Resize(nr) = u Cells(1, 1).Resize(nr, Columns.Count).Sort c, 1 Cells(1, 1).Resize(p, Columns.Count).Delete End Sub
Which do you mean? The code is easily modified to do either.
BrandonWLHI think I know why. 1st row is getting deleted and then the rng goes out of scope and its always empty as a result so it kick out of the loop. Duplicate the set rng line right under the delete line.