Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Finding a comment text

Hi all,

Is there a better way to find a certain comment text (say in a variable
named commtext) within a range than checking each cell in the range with an
If Cell.Comment.Text = commtext then
statement in a For each ... cycle?

Thanks,
Stefi

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default Finding a comment text

Hi Stefi:

Try

Dim comrng As Range, rng As Range
Set comrng = Cells.SpecialCells(xlCellTypeComments)
Const commtext = "???"
For Each rng In comrng
If rng.Comment.Text = commtext Then
MsgBox rng.Address(0, 0)
End If
Next

--
天行健,君*以自強不息
地勢坤,君*以厚德載物

http://www.vba.com.tw/plog/


"Stefi" wrote:

Hi all,

Is there a better way to find a certain comment text (say in a variable
named commtext) within a range than checking each cell in the range with an
If Cell.Comment.Text = commtext then
statement in a For each ... cycle?

Thanks,
Stefi

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Finding a comment text

Hi Stefi,

Try limiting the search to cells with comments, e.g.:

'============
Public Sub AAA()
Dim rng As Range
Dim rCell As Range
Const sStr As String = "Hi" '<<== Your search string

Set rng = Range("A1:D100").SpecialCells(xlCellTypeComments)
On Error GoTo 0

If Not rng Is Nothing Then
For Each rCell In rng.Cells
If InStr(1, rCell.Comment.Text, sStr, vbTextCompare) Then
'do something, e.g.:
MsgBox rCell.Address
End If
Next rCell
End If
End Sub
'<<============

---
Regards,
Norman


"Stefi" wrote in message
...
Hi all,

Is there a better way to find a certain comment text (say in a variable
named commtext) within a range than checking each cell in the range with
an
If Cell.Comment.Text = commtext then
statement in a For each ... cycle?

Thanks,
Stefi



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Finding a comment text

Hello,

you could use the Comments object

Dim ws As Worksheet, c As Comment

Set ws = ActiveSheet

For Each c In ws.Comments
Debug.Print c.Text
Next c

Regards,
Herbert

"Stefi" wrote:

Hi all,

Is there a better way to find a certain comment text (say in a variable
named commtext) within a range than checking each cell in the range with an
If Cell.Comment.Text = commtext then
statement in a For each ... cycle?

Thanks,
Stefi

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Finding a comment text

Yes, it reduces the range to be searched to comrng (cells that a comment is
assigned to).
Thank you!

Regards,
Stefi


chijanzen ezt *rta:

Hi Stefi:

Try

Dim comrng As Range, rng As Range
Set comrng = Cells.SpecialCells(xlCellTypeComments)
Const commtext = "???"
For Each rng In comrng
If rng.Comment.Text = commtext Then
MsgBox rng.Address(0, 0)
End If
Next

--
天行健,君*以自強不息
地勢坤,君*以厚德載物

http://www.vba.com.tw/plog/


"Stefi" wrote:

Hi all,

Is there a better way to find a certain comment text (say in a variable
named commtext) within a range than checking each cell in the range with an
If Cell.Comment.Text = commtext then
statement in a For each ... cycle?

Thanks,
Stefi



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Finding a comment text

Thank you, Norman and Herbert, both solution was new to me, both works
perfectly!

Regards,
Stefi


Herbert ezt *rta:

Hello,

you could use the Comments object

Dim ws As Worksheet, c As Comment

Set ws = ActiveSheet

For Each c In ws.Comments
Debug.Print c.Text
Next c

Regards,
Herbert

"Stefi" wrote:

Hi all,

Is there a better way to find a certain comment text (say in a variable
named commtext) within a range than checking each cell in the range with an
If Cell.Comment.Text = commtext then
statement in a For each ... cycle?

Thanks,
Stefi

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
Comment Text jwfothergill Excel Discussion (Misc queries) 2 August 4th 09 05:27 PM
Text from a comment box into a cell MFS Excel Worksheet Functions 2 May 7th 09 03:41 AM
Finding text in a cell and returning a value based on that text [email protected] Excel Discussion (Misc queries) 5 January 10th 07 06:01 PM
how to add text to a comment in VBA DB Excel Programming 3 November 4th 05 02:24 AM
Range's comment text Mircea Pleteriu Excel Programming 0 January 20th 05 10:36 AM


All times are GMT +1. The time now is 08:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"