Hi,
Apologies in advance, for the length of the post ...it's long, but what I'm trying to do, I hope, is quite simple.
I have a spreadsheet with a column (column A) of data where some of the cells in the column contain comments (i.e. the little boxes with text in that appear when you hover the cursor over the cell containing a comment). I'm wanting to copy the content of the cell's comment into the adjacent cell (i.e. the cell on the same row but in the next column, in this case column B). I've written a macro that seems to work, but only when I execute it a cell at a time (i.e. with no loop)
Sub Macro3()
Dim s as string
On Error Goto ErrorHandler
s = Activecell.Comment.Text
Activecell.Offset(0,1).Value = s
ErrorHandler:
Activecell.Offset(1,0).Select
End Sub
...the problem I'm encountering is when I try and loop the above macro (by inserting a for loop, see below)
Sub Macro3()
Dim s as String
Dim i, j as Integer
i = 10
For j = 1 to i
On Error Goto ErrorHandler
s = Activecell.Comment.Text
Activecell.Offset(0,1).Value = s
ErrorHandler:
Activecell.Offset(1,0).Select
Next
End Sub
...it crashes whenever it hits the second consecutive cell which doesn't contain a comment, with the following window popping up saying
"Object variable or With block variable not set"
...I'm totally stuck as to why the first macro works, but the second doesn't and I was hoping that someone might be able to help shed some light on my problem.
Any help/comments will be greatly appreciated.
Thanks,
Lochnagar
Apologies in advance, for the length of the post ...it's long, but what I'm trying to do, I hope, is quite simple.
I have a spreadsheet with a column (column A) of data where some of the cells in the column contain comments (i.e. the little boxes with text in that appear when you hover the cursor over the cell containing a comment). I'm wanting to copy the content of the cell's comment into the adjacent cell (i.e. the cell on the same row but in the next column, in this case column B). I've written a macro that seems to work, but only when I execute it a cell at a time (i.e. with no loop)
Sub Macro3()
Dim s as string
On Error Goto ErrorHandler
s = Activecell.Comment.Text
Activecell.Offset(0,1).Value = s
ErrorHandler:
Activecell.Offset(1,0).Select
End Sub
...the problem I'm encountering is when I try and loop the above macro (by inserting a for loop, see below)
Sub Macro3()
Dim s as String
Dim i, j as Integer
i = 10
For j = 1 to i
On Error Goto ErrorHandler
s = Activecell.Comment.Text
Activecell.Offset(0,1).Value = s
ErrorHandler:
Activecell.Offset(1,0).Select
Next
End Sub
...it crashes whenever it hits the second consecutive cell which doesn't contain a comment, with the following window popping up saying
"Object variable or With block variable not set"
...I'm totally stuck as to why the first macro works, but the second doesn't and I was hoping that someone might be able to help shed some light on my problem.
Any help/comments will be greatly appreciated.
Thanks,
Lochnagar