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 Transcribing cell formulas into their comment boxes

Hi guys,

Say, B1:E1 contain various formulas. I select B1:E1 and would like to
"transcribe" the formulas for the selected range directly into the
respective comment boxes, i.e. the comment boxes for B1:E1.

And if there happens to be no formulas in certain cells within the selected
range, I'll like a simple phrase: "No formula" to be written in the cpmment
box for those cells

Thanks
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----


  #2   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Transcribing cell formulas into their comment boxes

... what I'm after is for a sub to transfer the formulas as text into the
selected cells' comment boxes for safekeep/documentation purposes ..
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Transcribing cell formulas into their comment boxes

Hi Max,

Two for the price of one. I wouldn't want a comment if there is no
formula -Test1. But for your needs - Test2.

Sub Test1()
'deletes any comment if no formula
Dim cell As Range, sText As String, cm As Comment
For Each cell In Selection
With cell
Set cm = .Comment
If .HasFormula Then
sText = .Formula
If cm Is Nothing Then Set cm = .AddComment
cm.Visible = False
cm.Text Text:=sText
cm.Shape.Width = Len(sText) * 5 + 10
cm.Shape.Height = .Height * 1.2
ElseIf Not cm Is Nothing Then
cm.Delete
End If
End With
Set cm = Nothing
Next
End Sub

Sub Test2()
'include comment w/out formula
Dim cell As Range, sText As String, cm As Comment
Const s As String = "No Formula"
For Each cell In Selection
With cell
Set cm = .Comment
If cm Is Nothing Then Set cm = .AddComment
If .HasFormula Then
sText = .Formula
Else: sText = s
End If
cm.Visible = False
cm.Text Text:=sText
cm.Shape.Width = Len(sText) * 5 + 10
cm.Shape.Height = .Height * 1.2
End With
Set cm = Nothing
Next
End Sub

Would need to play around with the height / width stuff, assuming you want
to resize.

Regards,
Peter T


"Max" wrote in message
...
.. what I'm after is for a sub to transfer the formulas as text into the
selected cells' comment boxes for safekeep/documentation purposes ..
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----




  #4   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Transcribing cell formulas into their comment boxes

"Peter T" <peter_t@discussions wrote
....
Two for the price of one. ..


Great !! Many thanks, Peter. Runs smooth as silk.
It's a fantastic bargain, and I appreciate it <bg
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Transcribing cell formulas into their comment boxes

Would need to play around with the height / width stuff, assuming you want
to resize.


One technique to add to this excellent idea might be the use of "AutoSize."
Here's one example.

Sub Comment_Add_Formula()
'// = = = = = = = = = = = = = =
'// Within a selection...
'// Adds the Cells Formula to the Cells Comoment
'// If no Formula, adds the text..."No Formula"
'// = = = = = = = = = = = = = =

'//
Dim Cell As Range
Const Msg As String = "No Formula"
'//

On Error Resume Next

If TypeName(Selection) < "Range" Then Exit Sub

For Each Cell In Selection.Cells
With Cell
If .HasFormula Then
If .Comment Is Nothing Then
.AddComment .Formula
Else
.Comment.Text .Formula
End If
Else
If .Comment Is Nothing Then
.AddComment Msg
Else
.Comment.Text Msg
End If
End If
.Comment.Shape.TextFrame.AutoSize = True
.Comment.Visible = True
End With
Next Cell
End Sub


Just an idea. HTH
--
Dana DeLouis
Win XP & Office 2003


"Peter T" <peter_t@discussions wrote in message
...
Hi Max,

Two for the price of one. I wouldn't want a comment if there is no
formula -Test1. But for your needs - Test2.

Sub Test1()
'deletes any comment if no formula
Dim cell As Range, sText As String, cm As Comment
For Each cell In Selection
With cell
Set cm = .Comment
If .HasFormula Then
sText = .Formula
If cm Is Nothing Then Set cm = .AddComment
cm.Visible = False
cm.Text Text:=sText
cm.Shape.Width = Len(sText) * 5 + 10
cm.Shape.Height = .Height * 1.2
ElseIf Not cm Is Nothing Then
cm.Delete
End If
End With
Set cm = Nothing
Next
End Sub

Sub Test2()
'include comment w/out formula
Dim cell As Range, sText As String, cm As Comment
Const s As String = "No Formula"
For Each cell In Selection
With cell
Set cm = .Comment
If cm Is Nothing Then Set cm = .AddComment
If .HasFormula Then
sText = .Formula
Else: sText = s
End If
cm.Visible = False
cm.Text Text:=sText
cm.Shape.Width = Len(sText) * 5 + 10
cm.Shape.Height = .Height * 1.2
End With
Set cm = Nothing
Next
End Sub

Would need to play around with the height / width stuff, assuming you want
to resize.

Regards,
Peter T


"Max" wrote in message
...
.. what I'm after is for a sub to transfer the formulas as text into the
selected cells' comment boxes for safekeep/documentation purposes ..
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----








  #6   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Transcribing cell formulas into their comment boxes

"Dana DeLouis" wrote
....
Sub Comment_Add_Formula()


Thanks for the nice add-on, Dana !
It runs great (with autosizing) !

I did amend it a bit to hide the comments, though <g ..
..Comment.Visible = False

--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Transcribing cell formulas into their comment boxes

Dana,
Autosize, oh yes, much better than those height / width guestimates.

Only for personal aesthetic preference, I'd also include:
..Comment.Shape.Shadow.Visible = msoFalse

Max,
Two for the price of one. ..

It's a fantastic bargain, and I appreciate it <bg


Just disposing of old stock. New versions will include Dana's Autosize, at
full price of course!

Regards,
Peter T


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Transcribing cell formulas into their comment boxes

I think that's a great idea about removing the shadows from the comments. I
didn't think about that. It does look a little better! Thanks :)

--
Dana DeLouis
Win XP & Office 2003


"Peter T" <peter_t@discussions wrote in message
...
Dana,
Autosize, oh yes, much better than those height / width guestimates.

Only for personal aesthetic preference, I'd also include:
.Comment.Shape.Shadow.Visible = msoFalse


<snip


  #9   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Transcribing cell formulas into their comment boxes

Thanks for the nice add-ons, Dana and Peter !

To suit my use, I amended a bit to hide the comments:
..Comment.Visible = False

Terrific stuff ! Cheers.
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----


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
How do I create comment boxes that appear when a cell is clicked? pickpj Excel Worksheet Functions 2 May 10th 07 09:52 PM
Comment Boxes RWS Excel Discussion (Misc queries) 1 November 3rd 05 01:26 PM
Cell comment boxes shouldn't change size/shape unless changed by u sam Excel Discussion (Misc queries) 1 March 3rd 05 05:23 PM
comment boxes w-domo Excel Discussion (Misc queries) 1 January 21st 05 01:30 PM
Comment Boxes Rob Fenn Excel Programming 3 July 2nd 04 09:29 AM


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