Jump to content

Recommended Posts

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



  • 43 When would you like EduGeek EDIT 2025 to be held?

    1. 1. Select a time period you can attend


      • I can make it in June\July
      • I can make it in August\Sept
      • Other time period. Comment below
      • Either time

×
×
  • Create New...