Deleting Row Macro

  • Thread starter Thread starter Steve M
  • Start date Start date
S

Steve M

I have a spread sheet with data in A:A to G:G

I want a macro that will check the value in G and if its less than 3 to
delete that entire row and then move on to the next row and do the same
 
something like
for i = cells(rows.count,"a").end(xlup).row to 2 step -1
if cells(i,"a")<3 then rows(i).delete
next i
 
Insert a new column adjacent to your data and use it to insert row #s for all
your data. Now sort on column G so that all the rows less than 3 are in a
contiguous range. Delete them. Now sort on the rows numbers to restore your
data to its original order
 
I have a spread sheet with data in A:A to G:G

I want a macro that will check the value in G and if its less than 3 to
delete that entire row and then move on to the next row and do the same

One way.

First name the first cell in column G of your data as "StartRow"

I'm also assuming that there is something in all the cells in column
G. If not you'll need to change the lrows variable to something like
lrows=Range(Range("Startrow"),Range("G65536").End(xlUp)).Rows.Count


Sub DeleteGRowValue3()
Dim lRows As Long, x As Long
lRows=Range(Range("Startrow"),Range("Startrow").End(xlDown)).Rows.Count

For x = lRows To 1 Step -1
If Range("startrow").Offset(x - 1, 0) < 3 Then
Range("startrow").Offset(x - 1, 0).EntireRow.Delete
End If
Next

End Sub


__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________
 
Back
Top