Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 921
Default Deleting rows

I have a spreadsheet that is about 65000 rows. I need to create a macro that
will search column D for any number that is negative. I then need the the
row with the negative number and the row above it deleted.
Any help would be great.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Deleting rows

Hi,

Right click your sheet tab, view code and paste this in and run it

Sub delete_Me()
lastrow = Cells(Cells.Rows.Count, "D").End(xlUp).Row
For X = lastrow To 1 Step -1
If Cells(X, 4).Value < 0 Then
Rows(X).Delete
Rows(X - 1).Delete
End If
Next
End Sub

Mike

"Jeff" wrote:

I have a spreadsheet that is about 65000 rows. I need to create a macro that
will search column D for any number that is negative. I then need the the
row with the negative number and the row above it deleted.
Any help would be great.

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Deleting rows

Try the following code:



Sub AAA()
Dim StartRow As Long
Dim EndRow As Long
Dim DeleteThese As Range
Dim WS As Worksheet
Dim RowNdx As Long
Set WS = Worksheets("Sheet1")
With WS
EndRow = .Cells(.Rows.Count, "D").End(xlUp).Row
StartRow = 1
For RowNdx = EndRow To StartRow + 1 Step -1
If .Cells(RowNdx, "D").Value < 0 Then
If DeleteThese Is Nothing Then
Set DeleteThese = .Rows(RowNdx)
Else
Set DeleteThese = _
Application.Union(DeleteThese, .Rows(RowNdx))
End If
Set DeleteThese = _
Application.Union(DeleteThese, .Rows(RowNdx -
1))
End If
Next RowNdx
End With
If Not DeleteThese Is Nothing Then
DeleteThese.Delete
End If
End Sub



Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Fri, 28 Aug 2009 09:58:01 -0700, Jeff
wrote:

I have a spreadsheet that is about 65000 rows. I need to create a macro that
will search column D for any number that is negative. I then need the the
row with the negative number and the row above it deleted.
Any help would be great.

Thanks

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
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Links and Linking in Excel 1 November 13th 08 08:44 AM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Setting up and Configuration of Excel 1 November 12th 08 06:05 PM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Excel Worksheet Functions 1 November 12th 08 01:39 PM
Help!!! I have problem deleting 2500 rows of filtered rows shirley_kee[_2_] Excel Programming 1 January 12th 06 03:15 AM
deleting hidden rows so i can print only the rows showing?????? jenn Excel Worksheet Functions 0 October 6th 05 04:05 PM


All times are GMT +1. The time now is 12:32 AM.

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

About Us

"It's about Microsoft Excel"