browolf Posted February 15, 2011 Report Posted February 15, 2011 anyone a genius at excel vb? who can whip up a macro that reads a cell, reads the comment, counts the number of lines in the comment, then posts the result in the cell?
CESIL Posted February 15, 2011 Report Posted February 15, 2011 Do you want the count in the same cell?
browolf Posted February 15, 2011 Author Report Posted February 15, 2011 Do you want the count in the same cell? yes, same cell the comment is attached to
CESIL Posted February 15, 2011 Report Posted February 15, 2011 (edited) Try this...select the cell with comment and then Alt+F8 and run countLines Public Sub countLines() Dim vMyArray vMyArray = Split(ActiveCell.Comment.Text, Chr(10)) ActiveCell.Value = UBound(vMyArray) - LBound(vMyArray) + 1 End Sub EDIT: Sorry should have said... Alt+F11 double click on ThisWorkbook and paste the code. Then close VBA and try the above... Edited February 15, 2011 by CESIL
CESIL Posted February 15, 2011 Report Posted February 15, 2011 This version will work even if the cell has no comment attached Public Sub countLines() Dim vMyArray On Error GoTo noComment If Not ActiveCell.Comment.Text = "" Then vMyArray = Split(ActiveCell.Comment.Text, Chr(10)) ActiveCell.Value = UBound(vMyArray) - LBound(vMyArray) + 1 Exit Sub noComment: MsgBox "No comment found" End If End Sub 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now