View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default show Comment using INDEX

Maybe this will help you get started:

Option Explicit
'=index(array,row_num,column_num)
Function IndexComment(myRng As Range, _
Optional myRow As Long = 1, _
Optional myCol As Long = 1) As Variant

Dim res As Variant

Application.Volatile True

res = Application.Index(myRng, myRow, myCol)

IndexComment = res

With Application.Caller
If .Comment Is Nothing Then
'do nothing
Else
.Comment.Delete
End If

If myRng(myRow, myCol).Comment Is Nothing Then
'no comment, do nothing
Else
.AddComment Text:=myRng(myRow, myCol).Comment.Text
End If
End With

End Function

This kind of function could be one calculation behind. If the comment in the
table changes, then you'll want to force a recalculation before you believe the
results.

Application.volatile true
means that excel will recalculate each of these formulas each time excel
recalculates. You may notice a slowdown in your workbook.

If you remove this line, then the results in the cell will be ok, but the
comment may be wrong.

(The results in the cell should always be ok--it's the comment that's the
trouble.)

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

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=indexcomment(a1:c20,3,2)


Lucy wrote:

Hi there,

A B
1 Apple 44 (with red-arrow comment "fruit")
2 Pine 55
3 Apple 66
4 Orange 77

I've added comment "fruit" on cell B1
After I use INDEX function to locate B1, only the value in the cell shows
but NOT
the comments. Which means, only "44" shows.

How can I show the red-arrow comment "fruit" as well?

Thanks.


--

Dave Peterson