Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 6
Default How can I delete rows programmatically based on certain criteria?

I have a large dataset in Microsoft Excel 2003 with almost 3000 lines and
I want to delete the rows of it, which have nulls in one or more of their
columns.
e.g.
A B C D
1 2 3 4
1 4 5
2 3 4
Result : The 2nd and 3rd rows will be deleted or someway discarded.
How can I do this programmatically?
  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 4,624
Default How can I delete rows programmatically based on certain criteria?

One way:

Public Sub DeleteLinesWithNulls()
Const nCOLS As Long = 4
Dim rDelete As Range
Dim rCell As Range

For Each rCell In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
If Application.CountA(rCell.Resize(1, nCOLS)) < nCOLS Then
If rDelete Is Nothing Then
Set rDelete = rCell
Else
Set rDelete = Union(rDelete, rCell)
End If
End If
Next rCell
If Not rDelete Is Nothing Then rDelete.EntireRow.Delete
End Sub


In article ,
nt_artagnian wrote:

I have a large dataset in Microsoft Excel 2003 with almost 3000 lines and
I want to delete the rows of it, which have nulls in one or more of their
columns.
e.g.
A B C D
1 2 3 4
1 4 5
2 3 4
Result : The 2nd and 3rd rows will be deleted or someway discarded.
How can I do this programmatically?

  #3   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 694
Default How can I delete rows programmatically based on certain criteria?

JEMcG gave you the answer as asked.

Just as an aside it may be easier to do it with autofilter.
you can add an extra col with countblank and the row you want b1:d1
then auto filter it and slectg the ones 0. delete them.

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"nt_artagnian" wrote:

I have a large dataset in Microsoft Excel 2003 with almost 3000 lines and
I want to delete the rows of it, which have nulls in one or more of their
columns.
e.g.
A B C D
1 2 3 4
1 4 5
2 3 4
Result : The 2nd and 3rd rows will be deleted or someway discarded.
How can I do this programmatically?

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
Delete Rows based on criteria in excel Novaglory Excel Discussion (Misc queries) 5 July 10th 07 08:29 PM
How to delete lines programmatically if a condition is met? nt_artagnian[_2_] Excel Discussion (Misc queries) 1 March 7th 07 05:39 PM
delete part of a row based on certain criteria mark lane Excel Worksheet Functions 3 September 14th 06 01:16 AM
Delete rows based on criteria Chris_t_2k5 Excel Discussion (Misc queries) 2 April 11th 06 01:52 PM
Delete rows based on certain criteria Coal Miner Excel Discussion (Misc queries) 2 March 3rd 06 05:56 PM


All times are GMT +1. The time now is 12:59 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"