Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Catch Error in macro


I have following macro that I am using to delete entire row which has
blank cells or cells with exclamation mark. How do I go about catching
the errors that might be generated. One error that I am running into is
when there are no cells with either blank or exclamation marks?

Sub RowDelete(abc)
Worksheets(abc).Select
Columns("B:B").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete

Range("A2").Select
Selection.AutoFilter
Selection.AutoFilter Field:=2, Criteria1:="=*!*", Operator:=xlAnd
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.EntireRow.Delete
Selection.AutoFilter
End Sub

Thanks, Jay


--
sa02000
------------------------------------------------------------------------
sa02000's Profile: http://www.excelforum.com/member.php...o&userid=27747
View this thread: http://www.excelforum.com/showthread...hreadid=533738

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Catch Error in macro

Hi Jay,

try this

Columns("B:B").Select

'adding one row of code
Selection.Replace What:="=*!*", Replacement:="", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

'your original code continues
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete

and remove all the filtering

Ivan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Catch Error in macro


well I need to delete the entire row in which the ! is part of
value....
so I have cells containing data like
!2343
!6543
5848
8934
and so on.... so I need to delete those two first row completely....
what you suggested only replaces ! with blank and leaves rest of the
value in cell... so the cell is not blank.
Also, if I have data with no blanks I still get an error... so I still
need to catch that error.

Jay


--
sa02000
------------------------------------------------------------------------
sa02000's Profile: http://www.excelforum.com/member.php...o&userid=27747
View this thread: http://www.excelforum.com/showthread...hreadid=533738

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Catch Error in macro

Hi Jay,

Sub RowDelete(abc)
Worksheets(abc).Select

'here change where to look for "!", I used "Selection"
with Selection
..Replace What:="*!*", Replacement:="", LookAt:=xlPart
..SpecialCells(xlCellTypeBlanks).Select
..EntireRow.Delete
end with

Columns("B:B").SpecialCells(xlCellTypeBlanks).Enti reRow.Delete

End Sub

The idea is to replace cells containing "!" with blanks and then to
delete entire rows.

You don't need any filtering with this attitude.

If you still want to filter (for any other reason), use "on error
resume next" and "on error goto 0" statements in your code.



Regards,

Ivan

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Catch Error in macro

Sub RowDelete(abc)
Worksheets(abc).Select
Columns("B:B").Select
On Error Resume Next
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete
On Error goto 0

Range("A2").Select
Selection.AutoFilter
Selection.AutoFilter Field:=2, Criteria1:="=*!*", Operator:=xlAnd
On Error Resume Next
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.EntireRow.Delete
On Error goto 0
Selection.AutoFilter
End Sub

--
Regards,
Tom Ogilvy

"sa02000" wrote:


I have following macro that I am using to delete entire row which has
blank cells or cells with exclamation mark. How do I go about catching
the errors that might be generated. One error that I am running into is
when there are no cells with either blank or exclamation marks?

Sub RowDelete(abc)
Worksheets(abc).Select
Columns("B:B").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete

Range("A2").Select
Selection.AutoFilter
Selection.AutoFilter Field:=2, Criteria1:="=*!*", Operator:=xlAnd
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.EntireRow.Delete
Selection.AutoFilter
End Sub

Thanks, Jay


--
sa02000
------------------------------------------------------------------------
sa02000's Profile: http://www.excelforum.com/member.php...o&userid=27747
View this thread: http://www.excelforum.com/showthread...hreadid=533738




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 TO CATCH A DIFFERENT/INCONSISTENT FORMULA FARAZ QURESHI Excel Discussion (Misc queries) 3 February 17th 09 05:51 PM
how to catch the second or more cell with vlookup Valley Excel Worksheet Functions 8 April 24th 06 12:02 AM
How to catch the colorindex in a series leglouton Excel Programming 13 July 22nd 05 08:52 AM
How to catch the workbook names... LJi Excel Programming 6 July 20th 05 12:07 AM
Catch-22 with Error 59 Dan[_28_] Excel Programming 0 November 13th 03 05:11 AM


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