Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
darkwood
 
Posts: n/a
Default macro to insert comments?


I have a lookup function that I'd like to embed into a macro to place
the lookup result in a comment over a certain cell. Is this possible?
If so, how can I do it?


--
darkwood
------------------------------------------------------------------------
darkwood's Profile: http://www.excelforum.com/member.php...o&userid=29948
View this thread: http://www.excelforum.com/showthread...hreadid=506782

  #3   Report Post  
Posted to microsoft.public.excel.misc
darkwood
 
Posts: n/a
Default macro to insert comments?


I haven't used macros before, can you please elaborate?


--
darkwood
------------------------------------------------------------------------
darkwood's Profile: http://www.excelforum.com/member.php...o&userid=29948
View this thread: http://www.excelforum.com/showthread...hreadid=506782

  #4   Report Post  
Posted to microsoft.public.excel.misc
vezerid
 
Posts: n/a
Default macro to insert comments?

Hi darkwood,

I responded to a similar request in
microsoft.public.excel.worksheet.funtions a while back. In there I also
have the code. Do a search with the words:

vezerid comment VBA

See if the thread is any similar to your problem. If so, come back with
some information as to the structure of the lookup table that you have
in mind and I will be happy to make any modifications.

HTH
Kostis Vezerides

  #5   Report Post  
Posted to microsoft.public.excel.misc
darkwood
 
Posts: n/a
Default macro to insert comments?


I tried searching by that string, but only this post came up.


--
darkwood
------------------------------------------------------------------------
darkwood's Profile: http://www.excelforum.com/member.php...o&userid=29948
View this thread: http://www.excelforum.com/showthread...hreadid=506782



  #6   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default macro to insert comments?

This is from a previous post. Maybe it'll give you an idea:

You could write some code that could populate the comment with the results of an
=vlookup() function.

But if you change that part number, then the comment will be wrong until that
macro runs again.

This sounds like a nice idea until you start getting down to how many things can
go wrong (my opinion only).

If I were you, I'd just use an adjacent cell to contain that description.

But if you want a macro to do that:

Option Explicit
Sub AddCommentsToSelection()

Dim myRng As Range
Dim myCell As Range
Dim myLookupRng As Range
Dim lArea As Double
Dim res As Variant

Set myRng = Selection
Set myLookupRng = Worksheets("sheet2").Range("a:b")

For Each myCell In myRng.Cells
If myCell.Comment Is Nothing Then
'do nothing
Else
myCell.Comment.Delete
End If

res = Application.VLookup(myCell.Value, myLookupRng, 2, False)
If IsError(res) Then
'don't put anything there?
Else
myCell.AddComment Text:=res
With myCell.Comment
.Shape.TextFrame.AutoSize = True
If .Shape.Width 300 Then
lArea = .Shape.Width * .Shape.Height
.Shape.Width = 200
.Shape.Height = (lArea / 200) * 1.3
End If
End With
End If
Next myCell

End Sub

Just select the range to add the comments and run the macro.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

and I borrowed the resizing comment code from Debra Dalgleish's site:
http://www.contextures.com/xlcomments03.html#Resize


darkwood wrote:

I have a lookup function that I'd like to embed into a macro to place
the lookup result in a comment over a certain cell. Is this possible?
If so, how can I do it?

--
darkwood
------------------------------------------------------------------------
darkwood's Profile: http://www.excelforum.com/member.php...o&userid=29948
View this thread: http://www.excelforum.com/showthread...hreadid=506782


--

Dave Peterson
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
asking again, macro to insert rows Luke Excel Worksheet Functions 12 September 18th 05 06:32 PM
How do I insert a prompt into an Excel macro? TangoHammer Excel Discussion (Misc queries) 1 August 4th 05 09:31 PM
Insert macro into formula Paul Excel Worksheet Functions 1 May 12th 05 08:25 PM
Embedding an "insert row" macro with data validation Mr. G. Excel Worksheet Functions 0 April 11th 05 06:09 AM
How do I insert the date using a macro tara0801 Excel Discussion (Misc queries) 4 February 10th 05 09:09 PM


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