Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Function MatchCommentext()


Looking to build a function exactly like MATCH(), except that it would
evaluate the text of comments in a range.

If any comment in that range contained specific text in one cell, say
"MyText", then the function would return the column number of the cell in the
lookup range that contained the criteria comment text.

Example:
=MatchCommentext(criteria,lookuprange)

This function would go in cell a1.
In b1 would be the criteria ... MyText.
The lookup range could be b2.e2.
Cell c2 in the lookup range contains a comment with the same text as the
criteria cell [b1].
Therefore the function in this example would return a value of 2.

** Would a simpler variation be that it returned a value of TRUE or FALSE?
That would still work.

Thank you in advance for looking at this.


- Mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Function MatchCommentext()

One way:

Public Function MatchCommentText( _
criterion As String, rng As Range) As Variant
Dim rArea As Range
Dim i As Long
Dim sTest As String
Dim bFound As Boolean
On Error Resume Next
For i = 1 To rng.Count
sTest = rng(i).Comment.Text
If Not Err Then
If sTest = criterion Then
MatchCommentText = i
bFound = True
Exit For
End If
End If
Next i
On Error GoTo 0
If Not bFound Then MatchCommentText = CVErr(xlErrNA)
End Function

Note that if XL automatically inserts the username, that username, along
with ":" & a newline character are part of the text. One could modify
the function to ignore those characters, but it would likely also ignore
text in which those two characters appear.

You could also use a match if the value in the criterion exists anywhere
in a comment in the range by substituting

If sTest Like "*" & criterion & "*" Then

for

If sTest = criterion Then


In article ,
"MikeF" wrote:

Looking to build a function exactly like MATCH(), except that it would
evaluate the text of comments in a range.

If any comment in that range contained specific text in one cell, say
"MyText", then the function would return the column number of the cell in the
lookup range that contained the criteria comment text.

Example:
=MatchCommentext(criteria,lookuprange)

This function would go in cell a1.
In b1 would be the criteria ... MyText.
The lookup range could be b2.e2.
Cell c2 in the lookup range contains a comment with the same text as the
criteria cell [b1].
Therefore the function in this example would return a value of 2.

** Would a simpler variation be that it returned a value of TRUE or FALSE?
That would still work.

Thank you in advance for looking at this.


- Mike

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Function MatchCommentext()


Hello, and thank you for the reply.
I pasted the function in a regular module [presume that's where it goes..!].

On first attempt, it's returning an #N/A.
Here's the specifics ...

cell e153: =MATCHCommenTtext($E$149,AH153:CP153)
cell e149: MyText
cells ah153.cp153 are the lookup range.
cell ak153 contains a comment with MyText as the only text in it [no
username/etc].

PS ... I was incorrect in stating that returning TRUE or FALSE would work.
There needs to be a way to identify the cell address so a MATCH can be
performed on it.
Thanx again.

- Mike



"JE McGimpsey" wrote:

One way:

Public Function MatchCommentText( _
criterion As String, rng As Range) As Variant
Dim rArea As Range
Dim i As Long
Dim sTest As String
Dim bFound As Boolean
On Error Resume Next
For i = 1 To rng.Count
sTest = rng(i).Comment.Text
If Not Err Then
If sTest = criterion Then
MatchCommentText = i
bFound = True
Exit For
End If
End If
Next i
On Error GoTo 0
If Not bFound Then MatchCommentText = CVErr(xlErrNA)
End Function

Note that if XL automatically inserts the username, that username, along
with ":" & a newline character are part of the text. One could modify
the function to ignore those characters, but it would likely also ignore
text in which those two characters appear.

You could also use a match if the value in the criterion exists anywhere
in a comment in the range by substituting

If sTest Like "*" & criterion & "*" Then

for

If sTest = criterion Then


In article ,
"MikeF" wrote:

Looking to build a function exactly like MATCH(), except that it would
evaluate the text of comments in a range.

If any comment in that range contained specific text in one cell, say
"MyText", then the function would return the column number of the cell in the
lookup range that contained the criteria comment text.

Example:
=MatchCommentext(criteria,lookuprange)

This function would go in cell a1.
In b1 would be the criteria ... MyText.
The lookup range could be b2.e2.
Cell c2 in the lookup range contains a comment with the same text as the
criteria cell [b1].
Therefore the function in this example would return a value of 2.

** Would a simpler variation be that it returned a value of TRUE or FALSE?
That would still work.

Thank you in advance for looking at this.


- Mike


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Function MatchCommentext()

Works fine for me with your parameters. See

ftp://ftp.mcgimpsey.com/excel/mikef_demo.xls

In article ,
"MikeF" wrote:

Hello, and thank you for the reply.
I pasted the function in a regular module [presume that's where it goes..!].

On first attempt, it's returning an #N/A.
Here's the specifics ...

cell e153: =MATCHCommenTtext($E$149,AH153:CP153)
cell e149: MyText
cells ah153.cp153 are the lookup range.
cell ak153 contains a comment with MyText as the only text in it [no
username/etc].

PS ... I was incorrect in stating that returning TRUE or FALSE would work.
There needs to be a way to identify the cell address so a MATCH can be
performed on it.
Thanx again.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Function MatchCommentext()


If I can change a litte bit in midstream here..
I may be overcomplicating the requirement.
All that's needed is for the function to return the address of the cell that
contains the comment criteria.

So in this instance ...
cell e153: =MATCHCommenTtext($E$149,AH153:CP153)
cell e149: MyText
cells ah153.cp153 are the lookup range.
cell ak153 contains a comment with MyText as the only text in it [no
username/etc].
.... In the above example, the function in e153 would return ak153.
And so on for as other rows as required.

So cell e154: =MATCHCommenTtext($E$149,AH154:CP154)
cell e149: MyText
cells ah154.cp154 are the lookup range.
cell cb154 contains a comment with MyText as the only text in it.
.... In the above example, the function in e154 would return cb154.
And so on for as other rows as required.

Thanx again. Hope this change isn't too weird. :)

- Mike





"JE McGimpsey" wrote:

One way:

Public Function MatchCommentText( _
criterion As String, rng As Range) As Variant
Dim rArea As Range
Dim i As Long
Dim sTest As String
Dim bFound As Boolean
On Error Resume Next
For i = 1 To rng.Count
sTest = rng(i).Comment.Text
If Not Err Then
If sTest = criterion Then
MatchCommentText = i
bFound = True
Exit For
End If
End If
Next i
On Error GoTo 0
If Not bFound Then MatchCommentText = CVErr(xlErrNA)
End Function

Note that if XL automatically inserts the username, that username, along
with ":" & a newline character are part of the text. One could modify
the function to ignore those characters, but it would likely also ignore
text in which those two characters appear.

You could also use a match if the value in the criterion exists anywhere
in a comment in the range by substituting

If sTest Like "*" & criterion & "*" Then

for

If sTest = criterion Then


In article ,
"MikeF" wrote:

Looking to build a function exactly like MATCH(), except that it would
evaluate the text of comments in a range.

If any comment in that range contained specific text in one cell, say
"MyText", then the function would return the column number of the cell in the
lookup range that contained the criteria comment text.

Example:
=MatchCommentext(criteria,lookuprange)

This function would go in cell a1.
In b1 would be the criteria ... MyText.
The lookup range could be b2.e2.
Cell c2 in the lookup range contains a comment with the same text as the
criteria cell [b1].
Therefore the function in this example would return a value of 2.

** Would a simpler variation be that it returned a value of TRUE or FALSE?
That would still work.

Thank you in advance for looking at this.


- Mike




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
Excel Data Validation/Lookup function does function correcty Kirkey Excel Worksheet Functions 2 May 25th 09 09:22 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Offset function with nested match function not finding host ss. MKunert Excel Worksheet Functions 1 March 21st 06 10:46 PM
Adding a custom function to the default excel function list DonutDel Excel Programming 3 November 21st 03 03:41 PM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


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