View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Sandy Mann Sandy Mann is offline
external usenet poster
 
Posts: 2,345
Default What's wrong with this code?

Just my luck! I give up smoking then I get offered a cigar! <g Thanks
for the feedback.

--

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings


Replace @mailinator.com with @tiscali.co.uk


"access user" wrote in message
...
Hi Guys

Thanks to both of you for replying. Sandy you get the cigar. JLGWhiz -
that
still gave the same error. Only difference appears to be the 'On Error
Resume
Next' method. Don't understand why but thanks.

'G'day cobbers' - is that what they say over there? :-)

"Sandy Mann" wrote:

Try:

On Error Resume Next
If Selection.SpecialCells(xlConstants) Is Nothing Then
Exit Sub
Else
Selection.SpecialCells(xlConstants).ClearContents
End If
On Error GoTo 0

--
HTH

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings


Replace @mailinator.com with @tiscali.co.uk


"access user" wrote in message
...
If Selection.SpecialCells(xlConstants) Is Nothing Then
Exit Sub
Else
Selection.SpecialCells(xlConstants).ClearContents
End If

Basically, if the cells in question (either a selection or a range) are
already cleared then I do not want the sub run, otherwise I want it
run.
The
above is not trapping that condition as the last line before End If
always
runs and brings up the error 'no cells' - I do not want this error to
be
shown, just want the code to terminate in that case.

tia
James