![]() |
Macro to delete certain rows in a spreadsheet
I am working with a large spreadsheet and am trying to write a macro to
delete some of the rows in it. In my spreadsheet I am subtracting the data in column B from the data in column D, if the result is less than 6 I want to delete the entire row. I've found macros to delete blank rows and to delete rows based on a specific value in a cell, but I haven't found anything like what I need. Can somebody offer some assistance? Thank you. |
Macro to delete certain rows in a spreadsheet
Gary,
Here's one way: Sub test() Dim l As Long For l = Range("B65535").End(xlUp).Row To 1 Step -1 If (Range("D" & l).Value - Range("B" & l).Value) < 6 Then Rows(l).Delete End If Next l End Sub -- Hope that helps. Vergel Adriano "Gary" wrote: I am working with a large spreadsheet and am trying to write a macro to delete some of the rows in it. In my spreadsheet I am subtracting the data in column B from the data in column D, if the result is less than 6 I want to delete the entire row. I've found macros to delete blank rows and to delete rows based on a specific value in a cell, but I haven't found anything like what I need. Can somebody offer some assistance? Thank you. |
Macro to delete certain rows in a spreadsheet
How about:
Sub gary() n = Cells(Rows.Count, "B").End(xlUp).Row For m = n To 1 Step -1 If Cells(m, "D").Value - Cells(m, "B").Value < 6 Then Cells(m, "D").EntireRow.Delete End If Next End Sub -- Gary''s Student - gsnu200728 "Gary" wrote: I am working with a large spreadsheet and am trying to write a macro to delete some of the rows in it. In my spreadsheet I am subtracting the data in column B from the data in column D, if the result is less than 6 I want to delete the entire row. I've found macros to delete blank rows and to delete rows based on a specific value in a cell, but I haven't found anything like what I need. Can somebody offer some assistance? Thank you. |
All times are GMT +1. The time now is 02:24 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com