Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Enhancements to sub which writes cell value to comments

Need help for 2 modifications to the sub below

Within the selected range:
1. Empty cells or cells with formulas evaluating to "" (zero length null
strings) should not have any comments inserted.
2. For cells with existing comments prior to the sub's run, the cell results
are to be written as a new line below the text within the existing comments.
As-is the sub overwrites such cells with new comments.

Sub FormulaResultToComment()
'Joel .prog
For Each Cell In Selection
If Len(Cell.Formula) 0 Then
If Cell.Comment Is Nothing Then
Cell.AddComment
End If
'Cell.Comment.Text Text:=Cell.Formula
Cell.Comment.Text Text:=Cell.Value
End If
Next Cell
End Sub

Thanks
Max


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default Enhancements to sub which writes cell value to comments

see if this helps at all

Sub FormulaResultToComment()
'Joel .prog
Dim cell As Range
Dim cmt As String
For Each cell In Selection
If cell.Value 0 Or Len(cell.Address) = 0 Then
If cell.Comment Is Nothing Then
cell.AddComment "This is a test"
End If
cmt = cell.Comment.Text
cmt = cell.Comment.Text & vbCrLf & cell.Value
cell.Comment.Delete
cell.AddComment cmt
End If
Next cell
End Sub

--


Gary

"Max" wrote in message
...
Need help for 2 modifications to the sub below

Within the selected range:
1. Empty cells or cells with formulas evaluating to "" (zero length null
strings) should not have any comments inserted.
2. For cells with existing comments prior to the sub's run, the cell
results are to be written as a new line below the text within the existing
comments. As-is the sub overwrites such cells with new comments.

Sub FormulaResultToComment()
'Joel .prog
For Each Cell In Selection
If Len(Cell.Formula) 0 Then
If Cell.Comment Is Nothing Then
Cell.AddComment
End If
'Cell.Comment.Text Text:=Cell.Formula
Cell.Comment.Text Text:=Cell.Value
End If
Next Cell
End Sub

Thanks
Max


  #3   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Enhancements to sub which writes cell value to comments

Gary, thanks. Tried out your revision.

Within the selected range:
1. Empty cells or cells with formulas evaluating to "" (zero length null
strings) should not have any comments inserted.


a. Empty cells - ok. No comments are inserted.
b. Cells with formulas evaluating to "" (zero length null strings) - not ok.
It inserts a comment: "This is a test", instead of not inserting any
comment.

2. For cells with existing comments prior to the sub's run, the cell
results are to be written as a new line below the text within the
existing comments. As-is the sub overwrites such cells with new comments.


Item 2 is ok, but a new prob has surfaced. For cells w/o existing comments
which are not empty, the sub now writes the line: "This is a test" ahead of
the cell's value in the comment. The line: "This is a test" should not be
written.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Enhancements to sub which writes cell value to comments

max:

is this it?

Sub FormulaResultToComment()
'Joel .prog
Dim cell As Range
Dim cmt As String
For Each cell In Selection
If cell.Value 0 Or Len(cell.Address) = 0 Then
If cell.Comment Is Nothing Then
'do nothing
Else
cmt = cell.Comment.Text
cmt = cell.Comment.Text & Chr(10) & cell.Value
cell.Comment.Delete
cell.AddComment cmt
End If
End If
Next cell
End Sub


--


Gary


"Max" wrote in message
...
Gary, thanks. Tried out your revision.

Within the selected range:
1. Empty cells or cells with formulas evaluating to "" (zero length null
strings) should not have any comments inserted.


a. Empty cells - ok. No comments are inserted.
b. Cells with formulas evaluating to "" (zero length null strings) - not ok.
It inserts a comment: "This is a test", instead of not inserting any comment.

2. For cells with existing comments prior to the sub's run, the cell results
are to be written as a new line below the text within the existing comments.
As-is the sub overwrites such cells with new comments.


Item 2 is ok, but a new prob has surfaced. For cells w/o existing comments
which are not empty, the sub now writes the line: "This is a test" ahead of
the cell's value in the comment. The line: "This is a test" should not be
written.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---



  #5   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Enhancements to sub which writes cell value to comments

is this it?

Afraid not, Gary. Now there's no comments written into the selected range,
other than to those cells within it which contain existing comments.
Appreciate further advise.

Rgds
Max




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Enhancements to sub which writes cell value to comments

i thought that's what you wanted?
1. Empty cells or cells with formulas evaluating to "" (zero length null
strings) should not have any comments inserted
this works for me

2. For cells with existing comments prior to the sub's run, the cell results
are to be written as a new line below the text within the existing comments
this works for me

i don't see any criteria to add comments to any other cells.

please list all of your criteria.

--


Gary


"Max" wrote in message
...
is this it?


Afraid not, Gary. Now there's no comments written into the selected range,
other than to those cells within it which contain existing comments.
Appreciate further advise.

Rgds
Max



  #7   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Enhancements to sub which writes cell value to comments

i don't see any criteria to add comments to any other cells.
please list all of your criteria.


The missing part is the retention of the core functionality of the original
sub, which was to write cell values to comments. I sought the 2
modifications to the original sub, but its core functionality should be
retained. This seemed lost along the way.

Using your latest revision, when I run the sub on a range w/o any existing
comments but with formulas returning values other than null strings, nothing
happens. Thanks.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default Enhancements to sub which writes cell value to comments

here's another try:

cells with values 0 should now get a comment with the cell value
cells with values that have existing comments, should get the cell value
added to the end of the existing comment
cells that are blank or equate to 0 should not get comments.
let me know

Sub FormulaResultToComment()
'Joel .prog
Dim cell As Range
Dim cmt As String
For Each cell In Selection
If cell.Value = 0 Or Len(cell.Address) = 0 Then
'do nothing
ElseIf Not cell.Comment Is Nothing Then
cmt = cell.Comment.Text
cmt = cell.Comment.Text & Chr(10) & cell.Value
cell.Comment.Delete
cell.AddComment cmt
Else
cmt = cell.Value
cell.AddComment cmt
End If
Next cell
End Sub


--


Gary

"Max" wrote in message
...
i don't see any criteria to add comments to any other cells.
please list all of your criteria.


The missing part is the retention of the core functionality of the
original sub, which was to write cell values to comments. I sought the 2
modifications to the original sub, but its core functionality should be
retained. This seemed lost along the way.

Using your latest revision, when I run the sub on a range w/o any existing
comments but with formulas returning values other than null strings,
nothing happens. Thanks.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---


  #9   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Enhancements to sub which writes cell value to comments

First, many thanks for your patience, Gary.

Tried your latest rendition. It works 99% fine, great! The 1% off is that
for cells with formulas evaluating to "" (zero length null strings), there
were blank comments inserted. If it's difficult to get this last 1% settled,
think I could live with it. Appreciate your thoughts. Thanks.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Enhancements to sub which writes cell value to comments

maybe this?
Sub FormulaResultToComment()
'Joel .prog
Dim cell As Range
Dim cmt As String
For Each cell In Selection
If cell.Value = 0 Or Len(cell.Address) = 0 Or cell.Value = "" Then
'do nothing
ElseIf Not cell.Comment Is Nothing Then
cmt = cell.Comment.Text
cmt = cell.Comment.Text & Chr(10) & cell.Value
cell.Comment.Delete
cell.AddComment cmt
Else
cmt = cell.Value
cell.AddComment cmt
End If
Next cell
End Sub


--


Gary


"Max" wrote in message
...
First, many thanks for your patience, Gary.

Tried your latest rendition. It works 99% fine, great! The 1% off is that for
cells with formulas evaluating to "" (zero length null strings), there were
blank comments inserted. If it's difficult to get this last 1% settled, think
I could live with it. Appreciate your thoughts. Thanks.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---





  #11   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Enhancements to sub which writes cell value to comments

maybe this?
Yessss! That did it well. Super!
Thanks, Gary.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---


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
Empty Cell writes over full cell Carlo Excel Discussion (Misc queries) 2 December 1st 06 12:54 PM
formula that writes to a *different* cell? john Excel Worksheet Functions 2 September 19th 06 12:55 PM
2 VBA enhancements markx Excel Programming 4 July 4th 06 04:41 PM
Excel In-cell Enhancements silverliningboy Excel Worksheet Functions 4 May 15th 06 08:58 PM
Need Code Enhancements patrick molloy Excel Programming 1 July 17th 03 05:49 PM


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