PC Review


Reply
Thread Tools Rate Thread

delete a cell with a null value in column n

 
 
=?Utf-8?B?SmFuaXM=?=
Guest
Posts: n/a
 
      18th Jul 2007
There are some values in cells in column "M" that are blank. If the cell is
null or blank I want to delete the entire row. I borrowed this script and I
don't understand what the "Is Nothing" stands for. Does it stand for "null"?
How can I fix it to delete the rows I don't need.

thanks,



-----------code----------------
Sub deleteRows()

Dim Rng As Range
Dim rngToSearch As Range
Dim rngToDelete As Range


With ActiveSheet
Set rngToSearch = .Range(.Range("M1"), .Cells(Rows.Count, "M").End(xlUp))
End With

For Each Rng In rngToSearch
If IsNull Then
If rngToDelete Is Nothing Then
Set rngToDelete = Rng
Else
Set rngToDelete = Union(rngToDelete, Rng)
End If
End If
Next Rng

If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete

End Sub
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmFuaXM=?=
Guest
Posts: n/a
 
      18th Jul 2007
I put the if test wrong s/b if IsNull(rng).
I will repost.
sorry

"Janis" wrote:

> There are some values in cells in column "M" that are blank. If the cell is
> null or blank I want to delete the entire row. I borrowed this script and I
> don't understand what the "Is Nothing" stands for. Does it stand for "null"?
> How can I fix it to delete the rows I don't need.
>
> thanks,
>
>
>
> -----------code----------------
> Sub deleteRows()
>
> Dim Rng As Range
> Dim rngToSearch As Range
> Dim rngToDelete As Range
>
>
> With ActiveSheet
> Set rngToSearch = .Range(.Range("M1"), .Cells(Rows.Count, "M").End(xlUp))
> End With
>
> For Each Rng In rngToSearch
> If IsNull Then
> If rngToDelete Is Nothing Then
> Set rngToDelete = Rng
> Else
> Set rngToDelete = Union(rngToDelete, Rng)
> End If
> End If
> Next Rng
>
> If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
>
> End Sub

 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      18th Jul 2007
The whole thing can be done easier than that. Try this...

Sub DeleteBlanks()
On Error Resume Next
Columns("M").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
End Sub
--
HTH...

Jim Thomlinson


"Janis" wrote:

> I put the if test wrong s/b if IsNull(rng).
> I will repost.
> sorry
>
> "Janis" wrote:
>
> > There are some values in cells in column "M" that are blank. If the cell is
> > null or blank I want to delete the entire row. I borrowed this script and I
> > don't understand what the "Is Nothing" stands for. Does it stand for "null"?
> > How can I fix it to delete the rows I don't need.
> >
> > thanks,
> >
> >
> >
> > -----------code----------------
> > Sub deleteRows()
> >
> > Dim Rng As Range
> > Dim rngToSearch As Range
> > Dim rngToDelete As Range
> >
> >
> > With ActiveSheet
> > Set rngToSearch = .Range(.Range("M1"), .Cells(Rows.Count, "M").End(xlUp))
> > End With
> >
> > For Each Rng In rngToSearch
> > If IsNull Then
> > If rngToDelete Is Nothing Then
> > Set rngToDelete = Rng
> > Else
> > Set rngToDelete = Union(rngToDelete, Rng)
> > End If
> > End If
> > Next Rng
> >
> > If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
> >
> > End Sub

 
Reply With Quote
 
=?Utf-8?B?SmFuaXM=?=
Guest
Posts: n/a
 
      18th Jul 2007
Jim:
For some reason this compiles but it does not delete any of the rows. It
doesn't delete anything. In column "M" I have a necessary fields. If that
field is blank then I need the whole row removed so the report will make
sense. It looks like it should work but it doesn't do anything. Should I
have a loop?
Thanks,


"Jim Thomlinson" wrote:

> The whole thing can be done easier than that. Try this...
>
> Sub DeleteBlanks()
> On Error Resume Next
> Columns("M").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
> On Error GoTo 0
> End Sub
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Janis" wrote:
>
> > I put the if test wrong s/b if IsNull(rng).
> > I will repost.
> > sorry
> >
> > "Janis" wrote:
> >
> > > There are some values in cells in column "M" that are blank. If the cell is
> > > null or blank I want to delete the entire row. I borrowed this script and I
> > > don't understand what the "Is Nothing" stands for. Does it stand for "null"?
> > > How can I fix it to delete the rows I don't need.
> > >
> > > thanks,
> > >
> > >
> > >
> > > -----------code----------------
> > > Sub deleteRows()
> > >
> > > Dim Rng As Range
> > > Dim rngToSearch As Range
> > > Dim rngToDelete As Range
> > >
> > >
> > > With ActiveSheet
> > > Set rngToSearch = .Range(.Range("M1"), .Cells(Rows.Count, "M").End(xlUp))
> > > End With
> > >
> > > For Each Rng In rngToSearch
> > > If IsNull Then
> > > If rngToDelete Is Nothing Then
> > > Set rngToDelete = Rng
> > > Else
> > > Set rngToDelete = Union(rngToDelete, Rng)
> > > End If
> > > End If
> > > Next Rng
> > >
> > > If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
> > >
> > > End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to select rows by a null cell in a set column Dale Microsoft Excel Discussion 3 17th Jul 2009 08:09 PM
how can I return the value of the first not null cell in a column NHH Microsoft Excel Misc 6 19th Aug 2008 08:29 AM
Delete Rows if any cell in Column H is blank but do not Delete Fir =?Utf-8?B?bWFuZmFyZWVk?= Microsoft Excel Programming 4 28th Sep 2007 05:20 PM
Datagrid cell delete/esc combinations yield dll null reference exception =?Utf-8?B?SmFjayBIZXJy?= Microsoft Dot NET 0 9th Feb 2004 03:46 PM
searching for a null cell in a column =?Utf-8?B?RnV0dXJlV2l6?= Microsoft Excel Programming 4 8th Jan 2004 09:56 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:01 PM.