PC Review


Reply
Thread Tools Rate Thread

bulk transfer of comments using a range

 
 
DB042188
Guest
Posts: n/a
 
      9th Apr 2008
I'm trying to add comments to a range rather than one by one as follows...

Range(Cells(lRow, lOrigCol), Cells(lRow, lCol)).Comment = aRowComment

....in an effort to get better run times but get the following error

object variable or with block variable not set

....when I append .Text on the end of the command I get a compile error
saying assignment to a constant not permitted

aRowComment is an array of comments, built similarly to the array of values
currently transferring to the range with no problems.



 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      10th Apr 2008
I think you're going to have to loop through the cells and loop through the
comments.

Dim aRowComment As String
Dim myCell As Range
dim cCtr as long
dim aRowComment as variant

arowcomment = array("test","test2","test3")

cctr = lbound(arowcomment)
With ActiveSheet
with .Range(.Cells(lRow, lOrigCol), .Cells(lRow, lCol))
if .cells.count <> ubound(arowcomment) - lbound(arowcomment) + 1 then
'not enough comments for all the cells!
exit sub
end if

'clear existing comments
.ClearComments
For Each myCell In .Cells
myCell.AddComment Text:=aRowComment(cctr)
cctr = cctr + 1
Next myCell
End With
End With

I have no idea if this puts the comments where you want them--test it before you
trust it.

You may want to loop through each row--or loop through each column.



DB042188 wrote:
>
> I'm trying to add comments to a range rather than one by one as follows...
>
> Range(Cells(lRow, lOrigCol), Cells(lRow, lCol)).Comment = aRowComment
>
> ...in an effort to get better run times but get the following error
>
> object variable or with block variable not set
>
> ...when I append .Text on the end of the command I get a compile error
> saying assignment to a constant not permitted
>
> aRowComment is an array of comments, built similarly to the array of values
> currently transferring to the range with no problems.


--

Dave Peterson
 
Reply With Quote
 
DB042188
Guest
Posts: n/a
 
      10th Apr 2008
Dave, I'm trying to speed things up, is your solution faster than what we
already do which is to add them one by one as they come up thru a call to
something like ...

Private Sub InsertComment(lCol As Long, lRow As Long, sType As String,
sValue As String, lColor As Long)
Dim sTmpCell As String
Dim sComment As String

Const PROC_NAME = "InsertComment"

On Error GoTo ERR_HANDLER

sTmpCell = GetCellAddress(lCol, lRow)

With Range(sTmpCell)
If .Comment Is Nothing Then
.AddComment
.Comment.Text Text:=sType & sValue & vbNullString
Else
sComment = .Comment.Text
.Comment.Text Text:=sComment & vbLf & sType & sValue & vbNullString
End If
.Comment.Visible = False
.Comment.Shape.TextFrame.Characters.Font.Size = 8
.Comment.Shape.TextFrame.Characters.Font.Bold = False
.Comment.Shape.TextFrame.Characters.Font.Color = vbBlue
End With

Exit Sub

ERR_HANDLER:
Call AppError(err, MODULE_NAME, PROC_NAME)

End Sub

?


"Dave Peterson" wrote:

> I think you're going to have to loop through the cells and loop through the
> comments.
>
> Dim aRowComment As String
> Dim myCell As Range
> dim cCtr as long
> dim aRowComment as variant
>
> arowcomment = array("test","test2","test3")
>
> cctr = lbound(arowcomment)
> With ActiveSheet
> with .Range(.Cells(lRow, lOrigCol), .Cells(lRow, lCol))
> if .cells.count <> ubound(arowcomment) - lbound(arowcomment) + 1 then
> 'not enough comments for all the cells!
> exit sub
> end if
>
> 'clear existing comments
> .ClearComments
> For Each myCell In .Cells
> myCell.AddComment Text:=aRowComment(cctr)
> cctr = cctr + 1
> Next myCell
> End With
> End With
>
> I have no idea if this puts the comments where you want them--test it before you
> trust it.
>
> You may want to loop through each row--or loop through each column.
>
>
>
> DB042188 wrote:
> >
> > I'm trying to add comments to a range rather than one by one as follows...
> >
> > Range(Cells(lRow, lOrigCol), Cells(lRow, lCol)).Comment = aRowComment
> >
> > ...in an effort to get better run times but get the following error
> >
> > object variable or with block variable not set
> >
> > ...when I append .Text on the end of the command I get a compile error
> > saying assignment to a constant not permitted
> >
> > aRowComment is an array of comments, built similarly to the array of values
> > currently transferring to the range with no problems.

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      10th Apr 2008
They look pretty much equivalent to me. I would suspect that you wouldn't
notice a difference.

DB042188 wrote:
>
> Dave, I'm trying to speed things up, is your solution faster than what we
> already do which is to add them one by one as they come up thru a call to
> something like ...
>
> Private Sub InsertComment(lCol As Long, lRow As Long, sType As String,
> sValue As String, lColor As Long)
> Dim sTmpCell As String
> Dim sComment As String
>
> Const PROC_NAME = "InsertComment"
>
> On Error GoTo ERR_HANDLER
>
> sTmpCell = GetCellAddress(lCol, lRow)
>
> With Range(sTmpCell)
> If .Comment Is Nothing Then
> .AddComment
> .Comment.Text Text:=sType & sValue & vbNullString
> Else
> sComment = .Comment.Text
> .Comment.Text Text:=sComment & vbLf & sType & sValue & vbNullString
> End If
> .Comment.Visible = False
> .Comment.Shape.TextFrame.Characters.Font.Size = 8
> .Comment.Shape.TextFrame.Characters.Font.Bold = False
> .Comment.Shape.TextFrame.Characters.Font.Color = vbBlue
> End With
>
> Exit Sub
>
> ERR_HANDLER:
> Call AppError(err, MODULE_NAME, PROC_NAME)
>
> End Sub
>
> ?
>
> "Dave Peterson" wrote:
>
> > I think you're going to have to loop through the cells and loop through the
> > comments.
> >
> > Dim aRowComment As String
> > Dim myCell As Range
> > dim cCtr as long
> > dim aRowComment as variant
> >
> > arowcomment = array("test","test2","test3")
> >
> > cctr = lbound(arowcomment)
> > With ActiveSheet
> > with .Range(.Cells(lRow, lOrigCol), .Cells(lRow, lCol))
> > if .cells.count <> ubound(arowcomment) - lbound(arowcomment) + 1 then
> > 'not enough comments for all the cells!
> > exit sub
> > end if
> >
> > 'clear existing comments
> > .ClearComments
> > For Each myCell In .Cells
> > myCell.AddComment Text:=aRowComment(cctr)
> > cctr = cctr + 1
> > Next myCell
> > End With
> > End With
> >
> > I have no idea if this puts the comments where you want them--test it before you
> > trust it.
> >
> > You may want to loop through each row--or loop through each column.
> >
> >
> >
> > DB042188 wrote:
> > >
> > > I'm trying to add comments to a range rather than one by one as follows...
> > >
> > > Range(Cells(lRow, lOrigCol), Cells(lRow, lCol)).Comment = aRowComment
> > >
> > > ...in an effort to get better run times but get the following error
> > >
> > > object variable or with block variable not set
> > >
> > > ...when I append .Text on the end of the command I get a compile error
> > > saying assignment to a constant not permitted
> > >
> > > aRowComment is an array of comments, built similarly to the array of values
> > > currently transferring to the range with no problems.

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding colors, patterns, comments to large spreadsheets in bulk DB042188 Microsoft Excel Programming 2 9th Apr 2008 07:27 PM
Bulk Delete Comments with a Specific Phrase Refresher Microsoft Word Document Management 4 4th Apr 2008 10:09 PM
How to transfer emails from excel to bulk mailer Moving addresses from excel Microsoft Excel Misc 1 20th Dec 2007 02:54 PM
ADO Excel to Access - bulk transfer of array? =?Utf-8?B?UG9zdCBUZW5lYnJhcyBMdXg=?= Microsoft Excel Programming 3 12th Apr 2007 04:58 PM
Re: Batch or bulk editing of exif, IPTC, jpg comments or png tags? Google's friend Freeware 0 22nd Aug 2005 03:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:24 PM.