Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default If ActiveCell has a comment then exit sub

Trying to prevent error in the statement

If myAE = "Add" Then

and there is already a comment in the cell and the user tries to Add another comment.

Thanks,
Howard


Sub myAdd_myEdit_myDelete_Comment()
Dim myAdd, myEdit, myAE
Dim MyComment As String
Dim commentCell As Range
Dim cmt As Comment

myAE = InputBox("If adding comment enter ""Add""" _
& vbCr & vbCr & _
"If editing comment enter ""Edit""" _
& vbCr & vbCr & _
"If Deleting comment enter ""Delete""", "Comments")

If myAE = "Add" Then
ActiveSheet.Unprotect Password:=123

Set commentCell = ActiveCell
MyComment = InputBox("Enter your comments", "Comments")

Range(commentCell.Address).AddComment
Range(commentCell.Address).Comment.Text Text:=MyComment

ElseIf myAE = "Edit" Then
MyComment = InputBox("Enter your comments", "Comments")
ActiveCell.Comment.Text Text:=MyComment

ElseIf myAE = "Delete" Then
ActiveCell.Comment.Delete

ActiveSheet.Protect Password:=123
End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default If ActiveCell has a comment then exit sub

If Not ActiveCell.Comment Is Nothing Then Exit Sub

But what if the user wants to edit the existing comment?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default If ActiveCell has a comment then exit sub

On Monday, January 12, 2015 at 6:25:48 PM UTC-8, GS wrote:
If Not ActiveCell.Comment Is Nothing Then Exit Sub

But what if the user wants to edit the existing comment?


Well, of all things, that works. I thought for sure I tried that and was not getting the results I needed.

If you try to Add a comment in a cell where there is already one it exits sub, or else you can Edit the text or else you can Delete a comment.

Thanks for the help. I should have been able to do that myself!

Howard



Sub myAdd_myEdit_myDelete_Comment()
Dim myAdd, myEdit, myAE
Dim MyComment As String
Dim commentCell As Range
Dim cmt As Comment

myAE = InputBox("If adding comment enter ""Add""" _
& vbCr & vbCr & _
"If editing comment enter ""Edit""" _
& vbCr & vbCr & _
"If Deleting comment enter ""Delete""", "Comments")

If myAE = "Add" Then
'ActiveSheet.Unprotect Password:=123

Set commentCell = ActiveCell
MyComment = InputBox("Enter your comments", "Comments")

If Not ActiveCell.Comment Is Nothing Then Exit Sub

Range(commentCell.Address).AddComment

Range(commentCell.Address).Comment.Text Text:=MyComment

ElseIf myAE = "Edit" Then
MyComment = InputBox("Enter your comments", "Comments")
ActiveCell.Comment.Text Text:=MyComment

ElseIf myAE = "Delete" Then
ActiveCell.Comment.Delete

'ActiveSheet.Protect Password:=123
End If

End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default If ActiveCell has a comment then exit sub

I see you commented out the protection code. You do know that VBA works
on protected sheets when this parameter...

UserInterfaceOnly = True

...is set, right? Note that this is non persistent between sessions and
so protection must be reset (removed then replaced) at startup!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default If ActiveCell has a comment then exit sub

On Monday, January 12, 2015 at 7:57:01 PM UTC-8, GS wrote:
I see you commented out the protection code. You do know that VBA works
on protected sheets when this parameter...

UserInterfaceOnly = True

..is set, right? Note that this is non persistent between sessions and
so protection must be reset (removed then replaced) at startup!

--
Garry




No, I did not know that. Have not heard of it.

How would it be used in this code, perhaps like EnableEvents False/True at the beginning and end?

Howard


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default If ActiveCell has a comment then exit sub

No, I did not know that. Have not heard of it.

How would it be used in this code, perhaps like EnableEvents False/True at the beginning and end?

Howard


With some reading, seems it must be in a WorkBookOpen event.

If that is true, I will probably need to stay with the UnProtect/Protect method.

Howard

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default If ActiveCell has a comment then exit sub

Hi Howard,

Am Mon, 12 Jan 2015 17:13:24 -0800 (PST) schrieb L. Howard:

ElseIf myAE = "Edit" Then
MyComment = InputBox("Enter your comments", "Comments")
ActiveCell.Comment.Text Text:=MyComment


what if she wants to keep the existing text and add new text?


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default If ActiveCell has a comment then exit sub

Hi Howard,

Am Mon, 12 Jan 2015 17:13:24 -0800 (PST) schrieb L. Howard:

ElseIf myAE = "Edit" Then
MyComment = InputBox("Enter your comments", "Comments")
ActiveCell.Comment.Text Text:=MyComment


what if she wants to keep the existing text and add new text?


Regards
Claus B.


I was thinking same! I'd rename "Add" "New" and make "Edit" display
existing text for editing...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default If ActiveCell has a comment then exit sub

On Monday, January 12, 2015 at 11:12:33 PM UTC-8, Claus Busch wrote:
Hi Howard,

Am Mon, 12 Jan 2015 17:13:24 -0800 (PST) schrieb L. Howard:

ElseIf myAE = "Edit" Then
MyComment = InputBox("Enter your comments", "Comments")
ActiveCell.Comment.Text Text:=MyComment


what if she wants to keep the existing text and add new text?


Regards
Claus B.
--



That was not mentioned.

I messed with it a bit and can get the OLD text to a variable but can't get it to precede the NEW text in the code.

It has to be something like this but this won't fly...

ElseIf myAE = "Edit" Then
oldCmt = ActiveCell.Comment.Text

MyComment = InputBox("Enter your Comment NEW text...", "Comments")
ActiveCell.Comment.Text Text:=oldCmt & " " & Text:=MyComment

Howard
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default If ActiveCell has a comment then exit sub

Hi Howard,

Am Tue, 13 Jan 2015 00:30:14 -0800 (PST) schrieb L. Howard:

I messed with it a bit and can get the OLD text to a variable but can't get it to precede the NEW text in the code.


have a look:
https://onedrive.live.com/?cid=9378A...121822A3%21326
for "Comments"

The suggestion is realised with a modeless userform.


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default If ActiveCell has a comment then exit sub

have a look:
https://onedrive.live.com/?cid=9378A...121822A3%21326
for "Comments"

The suggestion is realised with a modeless userform.


Regards
Claus B.


Thanks for the example. A good learning tool.

Howard
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default If ActiveCell has a comment then exit sub

Hi Howard,

Am Tue, 13 Jan 2015 04:02:10 -0800 (PST) schrieb L. Howard:

Thanks for the example. A good learning tool.


you are welcome. I am always glad to help.
Do you have the latest version with the label above the textbox?


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default If ActiveCell has a comment then exit sub

I'd be inclined to go with a userform but it would help if you had some
basic understanding of the simple task of appending, prepending,
inserting, and replacing string values. As for your attempt here...

ElseIf myAE = "Edit" Then
oldCmt = ActiveCell.Comment.Text
MyComment = InputBox("Enter your comments", "Comments", oldCmt)
ActiveCell.Comment.Text Text:=MyComment

...where the existing comment text displays for the user to edit.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default If ActiveCell has a comment then exit sub

I'd be inclined to go with a userform but it would help if you had some
basic understanding of the simple task of appending, prepending,
inserting, and replacing string values. As for your attempt here...

ElseIf myAE = "Edit" Then
oldCmt = ActiveCell.Comment.Text
MyComment = InputBox("Enter your comments", "Comments", oldCmt)
ActiveCell.Comment.Text Text:=MyComment

...where the existing comment text displays for the user to edit.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


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
ActiveCell.Offset(i, 0) = Chr(ActiveCell.Row + 62) returns all A's Howard Excel Programming 5 December 25th 12 04:08 AM
Amend sub to re-hide comment when activecell change to another Max Excel Programming 4 January 4th 08 03:43 AM
Exit Field vs Exit Button...... roy_ware Excel Programming 2 October 10th 07 04:05 PM
If activecell.column = variable then activecell,offset (0,1) Battykoda via OfficeKB.com Excel Discussion (Misc queries) 1 October 2nd 07 08:05 PM
If a called sub exit, how to the caller exit right away? luvgreen[_4_] Excel Programming 4 February 24th 04 05:06 PM


All times are GMT +1. The time now is 05:56 AM.

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"