Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Cheese
 
Posts: n/a
Default Adding a new comment with a function?

Is there a method to add a comment to a particular cell by using a function
in another open cell?

I might write some comments in an adjacent empty cell (horizontally
speaking) because this is much faster than manually creating individual
comments. I would like to automatically apply those comments to another range
of cells, but as comments to those cells. Any ideas?
  #2   Report Post  
Norman Jones
 
Posts: n/a
Default

Hi Cheese,

The following macro inserts the text of each cell in rng1 into comments in
each cell in rng2. If the comments do not already exist, they are created.

Public Sub Tester03()
Dim rng1 As Range, rng2 As Range, rCell As Range
Dim sStr As String
Dim sh As Worksheet
Dim i As Long

Set sh = ActiveSheet '<<======= CHANGE
Set rng1 = sh.Range("A1:A20") '<<======= CHANGE
Set rng2 = rng1.Offset(0, 1) '<<======= CHANGE

For i = 1 To rng2.Cells.Count
sStr = rng1(i).Text
With rng2(i)
If .Comment Is Nothing Then .AddComment
.Comment.Text Text:=sStr
End With
Next

End Sub


---
Regards,
Norman



"Cheese" wrote in message
...
Is there a method to add a comment to a particular cell by using a
function
in another open cell?

I might write some comments in an adjacent empty cell (horizontally
speaking) because this is much faster than manually creating individual
comments. I would like to automatically apply those comments to another
range
of cells, but as comments to those cells. Any ideas?



  #3   Report Post  
Cheese
 
Posts: n/a
Default

Dear Norman,

Thanks for the help. Your macro worked great. Is there a way to resize the
comment if the text doesn't fill the box, so the comment doesn't appear any
larger than necessary? Sometimes it covers up other cells when it doesn't
need to.

Thanks!
  #4   Report Post  
Norman Jones
 
Posts: n/a
Default

Hi Cheese,

Is there a way to resize the comment if the text doesn't fill the box,
so the comment doesn't appear any larger than necessary?


Try this version which addresses the size issue. Note that the sizing code
is borrowed from an original Dave Peterson procedure.

'========================================
Public Sub Tester03A()
Dim rng1 As Range, rng2 As Range, rCell As Range
Dim sStr As String
Dim sh As Worksheet
Dim i As Long
Dim lArea As Long

Set sh = ActiveSheet '<<======= CHANGE
Set rng1 = sh.Range("A1:A20") '<<======= CHANGE
Set rng2 = rng1.Offset(0, 1) '<<======= CHANGE

For i = 1 To rng2.Cells.Count
sStr = rng1(i).Text
With rng2(i)
If .Comment Is Nothing Then .AddComment
.Comment.Text Text:=sStr
With .Comment
.Shape.TextFrame.AutoSize = True
If .Shape.Width 300 Then
lArea = .Shape.Width * .Shape.Height
.Shape.Width = 200
.Shape.Height = (lArea / 200) * 1.2
End If
End With
End With
Next

End Sub

'<<========================================

---
Regards,
Norman



"Cheese" wrote in message
...
Dear Norman,

Thanks for the help. Your macro worked great. Is there a way to resize the
comment if the text doesn't fill the box, so the comment doesn't appear
any
larger than necessary? Sometimes it covers up other cells when it doesn't
need to.

Thanks!



  #5   Report Post  
Norman Jones
 
Posts: n/a
Default

Hi Cheese,

And to avoid creating empty comments if no text is entered in the
corresponding comment text cell, try:

Public Sub Tester03B()
Dim rng1 As Range, rng2 As Range, rCell As Range
Dim sStr As String
Dim sh As Worksheet
Dim i As Long
Dim lArea As Long

Set sh = ActiveSheet '<<======= CHANGE
Set rng1 = sh.Range("A1:A20") '<<======= CHANGE
Set rng2 = rng1.Offset(0, 1) '<<======= CHANGE

For i = 1 To rng2.Cells.Count
sStr = rng1(i).Text
With rng2(i)
If Not IsEmpty(rng1(i)) Then
If .Comment Is Nothing Then .AddComment
.Comment.Text Text:=sStr
With .Comment
.Shape.TextFrame.AutoSize = True
If .Shape.Width 300 Then
lArea = .Shape.Width * .Shape.Height
.Shape.Width = 200
.Shape.Height = (lArea / 200) * 1.2
End If
End With
End If
End With
Next

End Sub

---
Regards,
Norman



"Cheese" wrote in message
...
Dear Norman,

Thanks for the help. Your macro worked great. Is there a way to resize the
comment if the text doesn't fill the box, so the comment doesn't appear
any
larger than necessary? Sometimes it covers up other cells when it doesn't
need to.

Thanks!





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
Workbook Protectionand stiil use Comment function olympiad Excel Discussion (Misc queries) 2 June 26th 05 02:41 AM
Excel option to store trendline's coefficients in cells for use Miguel Saldana Charts and Charting in Excel 9 June 20th 05 08:45 PM
Automatically up date time in a cell Mark Excel Discussion (Misc queries) 5 May 12th 05 12:26 AM
Adding default comment text dshigley Excel Discussion (Misc queries) 1 April 8th 05 05:26 PM
How to resize a comment box, by embedding code into a function? JJ Excel Worksheet Functions 13 November 16th 04 08:44 PM


All times are GMT +1. The time now is 08:51 PM.

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"