Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default What's wrong with this code?

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default What's wrong with this code?

Try this:

If Selection.SpecialCells(xlCellTypeConstants) Is Nothing Then
Exit Sub
Else
Selection.SpecialCells(xlCellTypeConstants).ClearC ontents
End If


"access user" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,345
Default What's wrong with this code?

Or rather:

On Error Resume Next
If Selection.SpecialCells(xlCellTypeConstants) Is Nothing Then
Exit Sub
Else
Selection.SpecialCells(xlCellTypeConstants).ClearC ontents
End If
On Error GoTo 0

(Got mixed up with JLGWhiz JLGWhiz's code)

--
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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default What's wrong with this code?

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






  #6   Report Post  
Posted to microsoft.public.excel.programming
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







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default What's wrong with this code?

If you're going to use "On error", why not just:

On Error Resume Next
Selection.SpecialCells(xlCellTypeConstants).ClearC ontents
On Error GoTo 0

===
But depending on what the selection is, I'd use:

On Error Resume Next
intersect(selection,Selection.SpecialCells(xlCellT ypeConstants)).ClearContents
On Error GoTo 0

it'll avoid any problems if a single cell is selected.

Sandy Mann wrote:

Or rather:

On Error Resume Next
If Selection.SpecialCells(xlCellTypeConstants) Is Nothing Then
Exit Sub
Else
Selection.SpecialCells(xlCellTypeConstants).ClearC ontents
End If
On Error GoTo 0

(Got mixed up with JLGWhiz JLGWhiz's code)

--
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


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default What's wrong with this code?

Thanks Dave - I'll look into that.
James

"Dave Peterson" wrote:

If you're going to use "On error", why not just:

On Error Resume Next
Selection.SpecialCells(xlCellTypeConstants).ClearC ontents
On Error GoTo 0

===
But depending on what the selection is, I'd use:

On Error Resume Next
intersect(selection,Selection.SpecialCells(xlCellT ypeConstants)).ClearContents
On Error GoTo 0

it'll avoid any problems if a single cell is selected.

Sandy Mann wrote:

Or rather:

On Error Resume Next
If Selection.SpecialCells(xlCellTypeConstants) Is Nothing Then
Exit Sub
Else
Selection.SpecialCells(xlCellTypeConstants).ClearC ontents
End If
On Error GoTo 0

(Got mixed up with JLGWhiz JLGWhiz's code)

--
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


--

Dave Peterson

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default What's wrong with this code?

These virtual cigars are quite good for you :-)

"Sandy Mann" wrote:

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








  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default What's wrong with this code?

This might be what you really wanted.

If Selection.SpecialCells(xlCellTypeConstants).Count < 1 Then
Exit Sub
Else
Selection.SpecialCells(xlCellTypeConstants).ClearC ontents
End If

"access user" wrote:

Thanks Dave - I'll look into that.
James

"Dave Peterson" wrote:

If you're going to use "On error", why not just:

On Error Resume Next
Selection.SpecialCells(xlCellTypeConstants).ClearC ontents
On Error GoTo 0

===
But depending on what the selection is, I'd use:

On Error Resume Next
intersect(selection,Selection.SpecialCells(xlCellT ypeConstants)).ClearContents
On Error GoTo 0

it'll avoid any problems if a single cell is selected.

Sandy Mann wrote:

Or rather:

On Error Resume Next
If Selection.SpecialCells(xlCellTypeConstants) Is Nothing Then
Exit Sub
Else
Selection.SpecialCells(xlCellTypeConstants).ClearC ontents
End If
On Error GoTo 0

(Got mixed up with JLGWhiz JLGWhiz's code)

--
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


--

Dave Peterson

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
What the F@#% is wrong with this code?? Finny[_3_] Excel Programming 8 July 19th 06 04:56 PM
HELP! What's wrong with my code? Sethaholic[_5_] Excel Programming 0 July 11th 05 07:43 PM
HELP! What's wrong with my code? Sethaholic[_6_] Excel Programming 0 July 11th 05 07:37 PM
What's wrong with the code,pls hv a look changeable[_4_] Excel Programming 1 November 3rd 04 02:57 AM
What's wrong with this bit of code Mervyn Thomas Excel Programming 7 January 22nd 04 03:56 PM


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