#1   Report Post  
Ken G.
 
Posts: n/a
Default Conditional Comment

I want to add a comment based on the contents of a particular cell. The
comment should either appear or not, depending on the cell value. I realise
this will require a macro, but don't know how to do this.

  #2   Report Post  
 
Posts: n/a
Default

Hi Ken,
Does this help?
Just as a demo, if the value in cell A1 of the active sheet changes to
become greater than 10 then Cell B1 has the comment "A1 is greater than
10" added.
The code must be pasted into the ThisWorkbook module. If you don't
want all sheets affected then paste the code into the WorkSheet_Change
Sub of the sheet you want affected.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
If ActiveSheet.Cells(1, 1).Value 10 Then
With ActiveSheet.Cells(1, 2)
On Error Resume Next 'if no comment to delete then error is
ignored
.Comment.Delete 'remove old comment
On Error GoTo 0
.AddComment
.Comment.Visible = True 'change to False if you only want to
see the comment
'when the cursor is positioned over the
commented cell
.Comment.Text Text:="A1 is greater than 10"
.Comment.Shape.TextFrame.AutoSize = True 'comment frame size
will suit any size comment
End With
Else: On Error Resume Next
ActiveSheet.Cells(1, 2).Comment.Delete 'delete old comment because A1
is not 10
On Error GoTo 0
End If
End Sub

Ken Johnson

  #3   Report Post  
Debra Dalgleish
 
Posts: n/a
Default

If you want a comment to appear as the value is being entered in the
cell, you can use DataValidation. On the first tab in the Data
Validation dialog box, enter your settings, and on the Error Alert tab,
enter the comment you want to appear for an invalid entry.

Ken G. wrote:
I want to add a comment based on the contents of a particular cell. The
comment should either appear or not, depending on the cell value. I realise
this will require a macro, but don't know how to do this.



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

  #4   Report Post  
Ken G.
 
Posts: n/a
Default

This is what I was looking for. Thanks Ken. The only problem I now have is
that although I've unprotected the comment in the format comment dropdown,
and I've re-sized it (commented out the auto size in the macro) when I
protect the sheet, the comment protection is re-set to on and my re-size
dimensions disapper. I'm assuming this is because its not an Excel comment
but one created by the macro. How do I overcome this?

" wrote:

Hi Ken,
Does this help?
Just as a demo, if the value in cell A1 of the active sheet changes to
become greater than 10 then Cell B1 has the comment "A1 is greater than
10" added.
The code must be pasted into the ThisWorkbook module. If you don't
want all sheets affected then paste the code into the WorkSheet_Change
Sub of the sheet you want affected.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
If ActiveSheet.Cells(1, 1).Value 10 Then
With ActiveSheet.Cells(1, 2)
On Error Resume Next 'if no comment to delete then error is
ignored
.Comment.Delete 'remove old comment
On Error GoTo 0
.AddComment
.Comment.Visible = True 'change to False if you only want to
see the comment
'when the cursor is positioned over the
commented cell
.Comment.Text Text:="A1 is greater than 10"
.Comment.Shape.TextFrame.AutoSize = True 'comment frame size
will suit any size comment
End With
Else: On Error Resume Next
ActiveSheet.Cells(1, 2).Comment.Delete 'delete old comment because A1
is not 10
On Error GoTo 0
End If
End Sub

Ken Johnson


  #5   Report Post  
 
Posts: n/a
Default

Ken G,
Sorry Ken I'm not sure what you can do about that.
Try a new posting for the real experts to have a look.
I wasn't even aware of the format comment drop down till you poited it
out.
Hope you get it sorted out.
Ken Johnson

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
VLOOKUP & Conditional Formating Help. Excel'ed Failures Excel Discussion (Misc queries) 6 August 16th 05 04:46 PM
2 Conditional formats and insert comment - ajit Ajit Munj Excel Discussion (Misc queries) 7 June 4th 05 05:39 AM
Adding default comment text dshigley Excel Discussion (Misc queries) 1 April 8th 05 05:26 PM
Conditional formatting not available in Excel BAB Excel Discussion (Misc queries) 2 January 1st 05 03:33 PM
comment indicators should feature lock or pw protect limiting acc. summer_rose Excel Worksheet Functions 1 December 3rd 04 07:02 AM


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