Got something to say or just want fewer pesky ads? Join us... 😊

MS Excel query



I've got a spreadsheet, with a few tabs, one of them has about 100 cells containing comments (lists, names etc).
Is there any way I can quickly export these out of the comments into a seperate sheet, or do I have to labouriously go in and copy and paste them out one by one?

Cheers
 




Acker79

Well-known member
NSC Patron
Nov 15, 2008
31,921
Brighton
You can highlight all the cells and copy and paste them all in one go.
 






clapham_gull

Legacy Fan
Aug 20, 2003
25,877
Yes very easily, but you'll need to know a bit of VBA.

I can probably knock you up a function to do it later this evening.
 






mcshane in the 79th

New member
Nov 4, 2005
10,485
I'm not aware of any way of copying the just text from the comment boxes, other than as Clapham Gull says by using VBA. But I'm not clever enough for that
 








clapham_gull

Legacy Fan
Aug 20, 2003
25,877
You need to create a module (if you know how to do that) and paste the following code.


Function ExtractComment(s As Range) As String
ExtractComment = Replace(s.Comment.Text, s.Comment.Author & ":", "", 1, 1)
End Function


To use it, just use it as a regular function referring to the cell where the comment is


For example if the comment is "over" cell A1, write in an empty cell


=ExtractComment(A1)



The way I've written it takes out the name of the author of the comment which is placed at the front. If you want to keep the author, do this instead


Function ExtractComment(s As Range) As String
ExtractComment = s.Comment.Text
End Function



If there isn't a comment the function will return an error (#Value), if you want it to simply return nothing, I'll fix it for you.
 
Last edited:






You need to create a module (if you know how to do that) and paste the following code.

Function ExtractComment(s As Range) As String
ExtractComment = Replace(s.Comment.Text, s.Comment.Author & ":", "", 1, 1)
End Function


To use it, just use it as a regular function referring to the cell where the comment is


For example if the comment is "over" cell A1, write in an empty cell

If there isn't a comment the function will return an error (#Value), if you want it to simply return nothing, I'll fix it for you.



=ExtractComment(A1)


The way I've written it takes out the name of the author of the comment which is placed at the front. If you want to keep the author, do this instead


Function ExtractComment(s As Range) As String
ExtractComment = s.Comment.Text
End Function

Brilliant stuff - thanks for that - I'll give it a go!:thumbsup:
 


clapham_gull

Legacy Fan
Aug 20, 2003
25,877
This function won't return an error if the caption is blank


Function ExtractComment(s As Range) As String

If Not s.Comment Is Nothing Then
ExtractComment = Replace(s.Comment.Text, s.Comment.Author & ":", "", 1, 1)
Else
ExtractComment = ""
End If

End Function
 






Albion and Premier League latest from Sky Sports


Top
Link Here