Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Run Time Error '91'

Hello,
The following code causes Run Time Error '91' when I insert it into
worksheets.
The code allows comments to be shown when cell is active.
Can anyone help?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("B4").Comment.Visible = Not (Intersect(Target, Range("B4")) Is
Nothing)
End Sub
Thanks in advance for any help,
Paul


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Run Time Error '91'

On 17 Jan., 17:47, Paul3rd wrote:
Hello,
The following code causes Run Time Error '91' when I insert it into
worksheets.
The code allows comments to be shown when cell is active.
Can anyone help?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
* *Range("B4").Comment.Visible = Not (Intersect(Target, Range("B4")) Is
Nothing)
End Sub
Thanks in advance for any help,
Paul


Hi Paul

The code is fine. Check if you have a comment in cell B4!

Regards,

Per
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Run Time Error '91'

Thanks for your quick reply.
You are correct!!
I didn't have a comment in the cell. Is there a way to modify the code so no
error is triggered if the cell is blank?
Thanks again,
Paul

"Per Jessen" wrote:

On 17 Jan., 17:47, Paul3rd wrote:
Hello,
The following code causes Run Time Error '91' when I insert it into
worksheets.
The code allows comments to be shown when cell is active.
Can anyone help?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("B4").Comment.Visible = Not (Intersect(Target, Range("B4")) Is
Nothing)
End Sub
Thanks in advance for any help,
Paul


Hi Paul

The code is fine. Check if you have a comment in cell B4!

Regards,

Per

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Run Time Error '91'

And you can check for a comment in B4 in code with:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Me.Range("B4").Comment Is Nothing Then
'don't try to use .visible
Else
Me.Range("B4").Comment.Visible _
= Not (Intersect(Target, Range("B4")) Is Nothing)
End If
End Sub




Paul3rd wrote:

Hello,
The following code causes Run Time Error '91' when I insert it into
worksheets.
The code allows comments to be shown when cell is active.
Can anyone help?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("B4").Comment.Visible = Not (Intersect(Target, Range("B4")) Is
Nothing)
End Sub
Thanks in advance for any help,
Paul


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Run Time Error '91'

On 17 Jan., 18:49, Paul3rd wrote:
Thanks for your quick reply.
You are correct!!
I didn't have a comment in the cell. Is there a way to modify the code so no
error is triggered if the cell is blank?
Thanks again,
Paul



"Per Jessen" wrote:
On 17 Jan., 17:47, Paul3rd wrote:
Hello,
The following code causes Run Time Error '91' when I insert it into
worksheets.
The code allows comments to be shown when cell is active.
Can anyone help?


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
* *Range("B4").Comment.Visible = Not (Intersect(Target, Range("B4")) Is
Nothing)
End Sub
Thanks in advance for any help,
Paul


Hi Paul


The code is fine. Check if you have a comment in cell B4!


Regards,


Per- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -


Hi Paul

Thanks for your reply!

This should do the trick

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Range("B4").Comment Is Nothing Then End
Range("B4").Comment.Visible = Not (Intersect(Target, Range("B4")) Is
Nothing)

End Sub

Regards,

Per


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Run Time Error '91'

Thanks Dave,
That worked perfectly.
Paul

"Dave Peterson" wrote:

And you can check for a comment in B4 in code with:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Me.Range("B4").Comment Is Nothing Then
'don't try to use .visible
Else
Me.Range("B4").Comment.Visible _
= Not (Intersect(Target, Range("B4")) Is Nothing)
End If
End Sub




Paul3rd wrote:

Hello,
The following code causes Run Time Error '91' when I insert it into
worksheets.
The code allows comments to be shown when cell is active.
Can anyone help?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("B4").Comment.Visible = Not (Intersect(Target, Range("B4")) Is
Nothing)
End Sub
Thanks in advance for any help,
Paul


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Run Time Error '91'

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Range("B4").Comment Is Nothing Then
Range("B4").Comment.Visible = Not (Intersect(Target, Range("B4")) _
Is Nothing)
End If
End Sub


"Paul3rd" wrote:

Thanks for your quick reply.
You are correct!!
I didn't have a comment in the cell. Is there a way to modify the code so no
error is triggered if the cell is blank?
Thanks again,
Paul

"Per Jessen" wrote:

On 17 Jan., 17:47, Paul3rd wrote:
Hello,
The following code causes Run Time Error '91' when I insert it into
worksheets.
The code allows comments to be shown when cell is active.
Can anyone help?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("B4").Comment.Visible = Not (Intersect(Target, Range("B4")) Is
Nothing)
End Sub
Thanks in advance for any help,
Paul


Hi Paul

The code is fine. Check if you have a comment in cell B4!

Regards,

Per

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
run time error 1004 general odbc error excel 2003 vba Mentos Excel Programming 5 January 24th 11 02:56 PM
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Run Time Error 1004: Application or Object Defined Error BEEJAY Excel Programming 4 October 18th 06 04:19 PM
Run Time 1004 Error: Application or Object Difine Error BEEJAY Excel Programming 0 October 17th 06 10:45 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM


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