Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default delete a cell with a null value in column n

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default delete a cell with a null value in column n

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default delete a cell with a null value in column n

The whole thing can be done easier than that. Try this...

Sub DeleteBlanks()
On Error Resume Next
Columns("M").SpecialCells(xlCellTypeBlanks).Entire Row.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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default delete a cell with a null value in column n

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).Entire Row.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
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 can I return the value of the first not null cell in a column NHH Excel Discussion (Misc queries) 7 August 19th 08 02:14 PM
Delete Null/Blank Rows Theresa Excel Discussion (Misc queries) 8 December 18th 07 05:17 AM
cell value based on null/not null in another cell spence Excel Worksheet Functions 1 February 18th 06 11:49 PM
Populating column N with a formula if column A is Null or Blank Steve Excel Programming 4 September 28th 04 01:50 PM
searching for a null cell in a column FutureWiz Excel Programming 4 January 8th 04 09:56 AM


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