Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to delete alternate rows in a spreadsheet? SI New Users to Excel 3 April 17th 08 10:19 AM
How do i delete empty rows in a spreadsheet Jim Excel Discussion (Misc queries) 2 July 19th 07 11:03 PM
Macro/VBA to delete rows in Spreadsheet Colin Foster[_5_] Excel Programming 5 June 17th 06 12:47 PM
delete all blank rows in a spreadsheet Richard Excel Programming 25 May 27th 06 07:47 AM
Is there a way to insert a formula, password or macro in an excel spreadsheet that will automatically delete the spreadsheet? oil_driller Excel Discussion (Misc queries) 1 February 8th 05 09:34 AM


All times are GMT +1. The time now is 09:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"