Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 504
Default getting 1 line of text from a cell comment

if a cell has a comment added that says:

Lineone
LineTwo

How can I have a msgbox that would only get the first line or second line of
that comment?

MsgBox ActiveCell.Comment.text??????

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default getting 1 line of text from a cell comment

You can use the Split function to separate the lines. For example...

Dim CommentLines() As String
CommentLines = Split(Range("A1").Comment.Text, vbLf)
MsgBox "Line1 = " & CommentLines(0)
MsgBox "Line2 = " & CommentLines(1)

Note that Split **always** returns a zero-based array (hence, the 0 and 1
array indexes).

By the way, you do not have to declare an array and then assign the output
from the Split function to it... since Split returns an array, you can
address its elements directly...

MsgBox "Line1 = " & Split(Range("A1").Comment.Text, vbLf)(0)
MsgBox "Line2 = " & Split(Range("A1").Comment.Text, vbLf)(1)

Of course, if you did not know how many lines there were, you would have to
use the array method and a loop...

Dim X As Long
Dim CommentLines() As String
CommentLines = Split(Range("A1").Comment.Text, vbLf)
For X = 0 To UBound(CommentLines)
MsgBox "Line " & (X + 1) & " = " & CommentLines(X)
Next

--
Rick (MVP - Excel)


"Kevin" wrote in message
...
if a cell has a comment added that says:

Lineone
LineTwo

How can I have a msgbox that would only get the first line or second line
of
that comment?

MsgBox ActiveCell.Comment.text??????

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 504
Default getting 1 line of text from a cell comment

Fantastic, Thanks so much!!!

"Rick Rothstein" wrote:

You can use the Split function to separate the lines. For example...

Dim CommentLines() As String
CommentLines = Split(Range("A1").Comment.Text, vbLf)
MsgBox "Line1 = " & CommentLines(0)
MsgBox "Line2 = " & CommentLines(1)

Note that Split **always** returns a zero-based array (hence, the 0 and 1
array indexes).

By the way, you do not have to declare an array and then assign the output
from the Split function to it... since Split returns an array, you can
address its elements directly...

MsgBox "Line1 = " & Split(Range("A1").Comment.Text, vbLf)(0)
MsgBox "Line2 = " & Split(Range("A1").Comment.Text, vbLf)(1)

Of course, if you did not know how many lines there were, you would have to
use the array method and a loop...

Dim X As Long
Dim CommentLines() As String
CommentLines = Split(Range("A1").Comment.Text, vbLf)
For X = 0 To UBound(CommentLines)
MsgBox "Line " & (X + 1) & " = " & CommentLines(X)
Next

--
Rick (MVP - Excel)


"Kevin" wrote in message
...
if a cell has a comment added that says:

Lineone
LineTwo

How can I have a msgbox that would only get the first line or second line
of
that comment?

MsgBox ActiveCell.Comment.text??????

Thanks



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
Challenge - Excel Line Feed Character CHR(10) - How to Delete and keep the text formatting without going ro single line in a cell ? No Name Excel Worksheet Functions 7 October 7th 09 11:10 AM
Text from a comment box into a cell MFS Excel Worksheet Functions 3 May 8th 09 08:43 PM
Text from a comment box into a cell MFS Excel Worksheet Functions 2 May 7th 09 03:41 AM
Create Cell Comment based on text in a cell on another worksheet Dave Fellman Excel Discussion (Misc queries) 2 March 15th 07 09:49 AM
A 2 line text showing up in the Cell in Excel prints in 1 line Danny Excel Discussion (Misc queries) 6 July 12th 05 08:47 PM


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