Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
cpf cpf is offline
external usenet poster
 
Posts: 1
Default Macro for Comment box

I am encoding 10 digit code on a comment box for most of my
worksheets. Question: how can I create a macro or any formula that
will identify comment boxes which has less than or more that 10 digit
codes? Hope you can help me. I badly need it to achieve accuracy of my
worsheet.
I can also be reached at YM, . I will keep my gtalk
activated in case u need further info. Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro for Comment box

This macro should work

Sub TestComments()

With ActiveSheet
Set LastCell = .Cells.SpecialCells(xlCellTypeLastCell)
Set UsedArea = Range("A1", LastCell)

For Each cell In UsedArea
If Not cell.Comment Is Nothing Then
Comment = cell.Comment.Text
'remove persons name
If InStr(Comment, ":") 0 Then
Comment = Mid(Comment, InStr(Comment, ":") + 1)
End If
If Len(Comment) < 10 Then
MsgBox (cell.Address & " : Comment has less than 10 characters")
End If
End If
Next cell
End With

End Sub


"cpf" wrote:

I am encoding 10 digit code on a comment box for most of my
worksheets. Question: how can I create a macro or any formula that
will identify comment boxes which has less than or more that 10 digit
codes? Hope you can help me. I badly need it to achieve accuracy of my
worsheet.
I can also be reached at YM, . I will keep my gtalk
activated in case u need further info. Thanks in advance

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro for Comment box

It is not clear if you have a single cell on each worksheet each of which
has a 10-digit code or if you have, say, a column of cells on each worksheet
each cell of which has a 10-digit code in them. Here is a macro which will
iterate all the worksheets in your workbook, looking in Column B on each
worksheet to see if there is comment whose last line (meaning you can have a
name and even a description before the last line) is not 10 digits long and,
if any are found, a MessageBox for each one is displayed showing the
worksheet and cell address.

Sub CheckComments()
Dim C As Comment
Dim WS As Worksheet
Dim ComText() As String
For Each WS In Worksheets
For Each C In WS.Comments
If C.Parent.Column = 2 Then
ComText = Split(Trim(Replace(C.Text, vbLf, " ")))
If Not ComText(UBound(ComText)) Like "##########" Then
MsgBox "Comment on " & WS.Name & " at " & _
C.Parent.Address & vbLf & vbLf & _
"***************" & vbLf & C.Text & vbLf & _
"***************" & vbLf & vbLf & _
"is not 10 character long."
End If
End If
Next
Next
End Sub

If you are looking for only a single cell on each worksheet instead of a
column of cells, then change this line...

If C.Parent.Column = 2 Then

to this instead...

If C.Parent.Address = "$B$5" Then

where you would substitute your cell's address (in absolute form as shown)
for my $B$5 example.

Rick


"cpf" wrote in message
...
I am encoding 10 digit code on a comment box for most of my
worksheets. Question: how can I create a macro or any formula that
will identify comment boxes which has less than or more that 10 digit
codes? Hope you can help me. I badly need it to achieve accuracy of my
worsheet.
I can also be reached at YM, . I will keep my gtalk
activated in case u need further info. Thanks in advance


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro for Comment box

If you are looking for only a single cell on each worksheet instead of a
column of cells, then change this line...

If C.Parent.Column = 2 Then

to this instead...

If C.Parent.Address = "$B$5" Then

where you would substitute your cell's address (in absolute form as shown)
for my $B$5 example.


Actually, if you only have one comment per worksheet that you want to check,
this code is probably more efficient...

Sub CheckComments()
Dim C As Comment
Dim WS As Worksheet
Dim ComText() As String
For Each WS In Worksheets
Set C = WS.Range("B5").Comment
ComText() = Split(Trim(Replace(C.Text, vbLf, " ")))
If Not ComText(UBound(ComText)) Like "##########" Then
MsgBox "Comment on " & WS.Name & " at " & C.Parent.Address & _
vbLf & vbLf & "***************" & vbLf & C.Text & vbLf & _
"***************" & vbLf & vbLf & "is not 10 character long."
End If
Next
End Sub

Rick

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
macro to insert a comment driller Excel Worksheet Functions 0 February 8th 07 10:22 PM
having a macro insert a comment jhahes[_31_] Excel Programming 1 September 20th 05 10:37 PM
Macro to Insert Comment to a cell wojo Excel Programming 14 July 22nd 05 02:50 PM
Macro to Insert Comment to a cell wojo Excel Programming 0 July 21st 05 04:06 PM
FORMAT COMMENT TEXT WITH MACRO Sunil Patel Excel Programming 4 June 30th 05 05:13 PM


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