Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Felix
 
Posts: n/a
Default VBA ON ERROR does not work with SPECIALCELLS

I have a problem trapping errors using
"On Error goto ..." or "On Error Resume Next"

"On Error ..." works everywhere except when the offending
command uses SpecialCells as in
Selection.SpecialCells(xlCellTypeBlanks).Select

when not found, the macro errors with Run-time error 1004.

The same macros worked fine in xl2000 until I had to
install the hotfix from MS Support article 815406. Then
the problem started. Just upgraded to xl2003 but the
problem remains.

All the MS support articles refer only to protected sheets
which does not apply. Any ideas on a workaround?
  #2   Report Post  
Fredrik Wahlgren
 
Posts: n/a
Default


"Felix" wrote in message
...
I have a problem trapping errors using
"On Error goto ..." or "On Error Resume Next"

"On Error ..." works everywhere except when the offending
command uses SpecialCells as in
Selection.SpecialCells(xlCellTypeBlanks).Select

when not found, the macro errors with Run-time error 1004.

The same macros worked fine in xl2000 until I had to
install the hotfix from MS Support article 815406. Then
the problem started. Just upgraded to xl2003 but the
problem remains.

All the MS support articles refer only to protected sheets
which does not apply. Any ideas on a workaround?


I think you have to loop over the selection and make sure there's at least
one blank cell.

/Fredrik


  #3   Report Post  
Harlan Grove
 
Posts: n/a
Default

Felix wrote...
I have a problem trapping errors using
"On Error goto ..." or "On Error Resume Next"

"On Error ..." works everywhere except when the offending
command uses SpecialCells as in
Selection.SpecialCells(xlCellTypeBlanks).Select

when not found, the macro errors with Run-time error 1004.

....

This *should* give an untrappable runtime error. When there are no
blank cells, .SpecialCells doesn't return a range object, so the
following .Select method call is invalid.

You need to use two steps to trap potential failure by .SpecialCells.


Dim r As Range

On Error Resume Next
Set r = Selection.SpecialCells(xlCellTypeBlanks)
Err.Clear
On Error GoTo 0

If r Is Nothing Then
MsgBox "No blank cells"
Else
r.Select
End If

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
Spin button in a work sheet - how do I make it work? [email protected] Excel Worksheet Functions 1 April 7th 05 08:43 PM
How to get saved old saved work that was saved over? Maral Excel Discussion (Misc queries) 1 February 20th 05 08:59 PM
Change Path names in copied work book jheaney Excel Worksheet Functions 2 November 18th 04 07:29 PM
how is possible working on work sheet by two person in the netwo. Ben Excel Worksheet Functions 1 November 18th 04 02:39 AM
How do I ensure dates inputted are during the work week? Jim Johnson Excel Worksheet Functions 3 October 29th 04 08:25 AM


All times are GMT +1. The time now is 12:19 AM.

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"