Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

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?

Posted (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 by CESIL
Posted

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

  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...