Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default while deleting rows it finds an error - error trapping

Okay, my code seems to be working but it stops after deleting the first two
rows.
It must find an error then return to 0 but what is the error? The only
thing I see is there are two cells together in column M that are blank.
There are a whold bunch more. HOw do I trap for the error so this script
will finish.
thanks, sorry for the multiple posts.
-----------code------
Sub DeleteRowsBlankMColumns()
With ActiveSheet
On Error Resume Next
.Columns("M").SpecialCells(xlCellTypeBlanks).Entir eRow.Delete
On Error GoTo 0
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default while deleting rows it finds an error - error trapping

From your previous post give this a try. It is probalby not an error but
rather blank space characters or the blanks are the result of a formula...

How about this. It should delete all of the blank whether they are the result
of a formula or if the cell contains blank spaces... It is similar to what
you first posted...

Sub DeleteBlanks()
Dim rngToSearch As Range
Dim rng As Range
Dim rngToDelete As Range

With ActiveSheet
On Error Resume Next
Columns("M").SpecialCells(xlCellTypeBlanks).Entire Row.Delete
On Error GoTo 0

Set rngToSearch = .Range(.Range("M1"), .Cells(Rows.Count, "M").End(xlUp))
For Each rng In rngToSearch
If Trim(rng.Value) = "" Then
If rngToDelete Is Nothing Then
Set rngToDelete = rng
Else
Set rngToDelete = Union(rng, rngToDelete)
End If
Next rng
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End With
End Sub

--
HTH...

Jim Thomlinson


"Janis" wrote:

Okay, my code seems to be working but it stops after deleting the first two
rows.
It must find an error then return to 0 but what is the error? The only
thing I see is there are two cells together in column M that are blank.
There are a whold bunch more. HOw do I trap for the error so this script
will finish.
thanks, sorry for the multiple posts.
-----------code------
Sub DeleteRowsBlankMColumns()
With ActiveSheet
On Error Resume Next
.Columns("M").SpecialCells(xlCellTypeBlanks).Entir eRow.Delete
On Error GoTo 0
End With
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default while deleting rows it finds an error - error trapping

That is a very nice script. I am sure there is dirty data in it. It comes
from a SQL server or is downloaded as a report. This company uses excel for
everything instead of databases. some files they copy several times. tnx,
"Jim Thomlinson" wrote:

From your previous post give this a try. It is probalby not an error but
rather blank space characters or the blanks are the result of a formula...

How about this. It should delete all of the blank whether they are the result
of a formula or if the cell contains blank spaces... It is similar to what
you first posted...

Sub DeleteBlanks()
Dim rngToSearch As Range
Dim rng As Range
Dim rngToDelete As Range

With ActiveSheet
On Error Resume Next
Columns("M").SpecialCells(xlCellTypeBlanks).Entire Row.Delete
On Error GoTo 0

Set rngToSearch = .Range(.Range("M1"), .Cells(Rows.Count, "M").End(xlUp))
For Each rng In rngToSearch
If Trim(rng.Value) = "" Then
If rngToDelete Is Nothing Then
Set rngToDelete = rng
Else
Set rngToDelete = Union(rng, rngToDelete)
End If
Next rng
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End With
End Sub

--
HTH...

Jim Thomlinson


"Janis" wrote:

Okay, my code seems to be working but it stops after deleting the first two
rows.
It must find an error then return to 0 but what is the error? The only
thing I see is there are two cells together in column M that are blank.
There are a whold bunch more. HOw do I trap for the error so this script
will finish.
thanks, sorry for the multiple posts.
-----------code------
Sub DeleteRowsBlankMColumns()
With ActiveSheet
On Error Resume Next
.Columns("M").SpecialCells(xlCellTypeBlanks).Entir eRow.Delete
On Error GoTo 0
End With
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
Deleting a range of rows based on a variable; syntax error Babymech Excel Discussion (Misc queries) 3 January 16th 09 06:19 PM
runtime 1004 error on deleting rows with blank cells Janis Excel Programming 5 July 18th 07 09:38 PM
Error when deleting rows wmureports Excel Programming 1 June 30th 06 08:19 PM
Code deleting all rows in error JOUIOUI Excel Programming 3 June 10th 06 08:39 PM
Deleting rows based upon Error conditions JEff Excel Programming 1 December 28th 04 09:55 PM


All times are GMT +1. The time now is 05:31 PM.

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

About Us

"It's about Microsoft Excel"