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

Hello,

I dabble in Word VBA but today I am challenged with an Excel
spreadsheet and find myself hopelessly lost.

Until corrected I will refer to the spreadsheet grid as rows and
columns. I have many rows and many columns. The value in column "P"
is either 1 or 0. I want to delete any row that has a "P" column value
of 0.

This is my attempt at logical thought but it doesn't work. Please
help.

Sub DeleteRows()

For Each oRow in ActiveSheet.Rows
If ActiveSheet.Columns("P").value = 0 Then
oRow.Delete
End If
Next oRow

End Sub

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

Hi Greg

I have examples on this page
http://www.rondebruin.nl/delete.htm

If you need more help post back
Check out the Autofilter example first (fast)

--
Regards Ron de Bruin
http://www.rondebruin.nl


"Greg http://gregmaxey.mvps.org/word_tips.htm" wrote in message
oups.com...
Hello,

I dabble in Word VBA but today I am challenged with an Excel
spreadsheet and find myself hopelessly lost.

Until corrected I will refer to the spreadsheet grid as rows and
columns. I have many rows and many columns. The value in column "P"
is either 1 or 0. I want to delete any row that has a "P" column value
of 0.

This is my attempt at logical thought but it doesn't work. Please
help.

Sub DeleteRows()

For Each oRow in ActiveSheet.Rows
If ActiveSheet.Columns("P").value = 0 Then
oRow.Delete
End If
Next oRow

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Deleting rows with VBA

Ron,

Perfect. Thank you very much. The Autofilter example was both fast
and simple.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Deleting rows with VBA

Greg,

How about something like this?

Sub DeleteRowsWithPequalZero()

Dim TestRow As Range

For Each TestRow In Range("A1:A100")
If Range("P" & TestRow.Row).Value = 0 Then
TestRow.EntireRow.Delete
End If
Next

End Sub

Don't use activesheet.rows, otherwise you'll be testing right down to row
65536!
You could also subsitute a Range Name instead of cell references:

For Each TestRow In Range("MyTestRange")

Hope this helps

Pete





"Greg http://gregmaxey.mvps.org/word_tips" wrote:

Hello,

I dabble in Word VBA but today I am challenged with an Excel
spreadsheet and find myself hopelessly lost.

Until corrected I will refer to the spreadsheet grid as rows and
columns. I have many rows and many columns. The value in column "P"
is either 1 or 0. I want to delete any row that has a "P" column value
of 0.

This is my attempt at logical thought but it doesn't work. Please
help.

Sub DeleteRows()

For Each oRow in ActiveSheet.Rows
If ActiveSheet.Columns("P").value = 0 Then
oRow.Delete
End If
Next oRow

End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Deleting rows with VBA

Pete,

Yes, that works well too. 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 Excel Discussion (Misc queries) 1 January 12th 06 03:24 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 01:44 PM.

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"