Link to home
Start Free TrialLog in
Avatar of Hammer8
Hammer8Flag for United States of America

asked on

Is there a maximum number of cell comments an Excel 2010 spreadsheet can have?

Hi, I have some VBA code which loops through data in a spreadsheet and depending on a set of criteria, adds comments to each cell if appropriate.  This works well and the code works.  However, after a certain number of cells, the code returns an error 91 when trying to execute:

currentcell.comment.add

I can't think of why this would break after thousands of comments added using the same code and in fact, if I delete some data, then the code can run past the cell where the last error occurred (and so it's not breaking at the same place each time).

And so the only thing I can think of is if there's a maximum number of comments that can be in a spreadsheet, but I can't seem to find any documentation of this.

Any ideas?

Thanks,

Hammer8
Avatar of theruck
theruck
Flag of Slovakia image

are you able to write a comment after the vbs stops?
then maybe some other limit.
http://office.microsoft.com/en-gb/excel-help/excel-specifications-and-limits-HP010342495.aspx
By experiment using the following macro there is no limit. C got to 66000 and stopped gracefully. The last value shown in the Immediate window was 66000.

Sub doit()
Dim c As Long

For c = 1 To 66000
    Debug.Print c
    Cells(c, 5).AddComment "comment"
Next
End Sub

Open in new window

I ran the above to 100,000 with no problems. If you want to try it yourself I suggest turning off screen updating. e.g.
Sub doit()
Dim c As Long
Application.ScreenUpdating = False
For c = 1 To 66000
    Debug.Print c
    Cells(c, 5).AddComment "comment"
Next
End Sub
Application.ScreenUpdating = True

Open in new window

I'm reading Err91 as "Object or With Variable not set".

If it is infact on that line, then it would seem "CurrentCell" is not set. Check if its equal to Nothing on the failed case, and if so, track back to where it should have been set and figure out why it wasn't.
Avatar of Hammer8

ASKER

Thank you all for your help.  I was able to track the problem down to a problem of "too much formatting" in the spreadsheet (either actual formatting or a new cell comment).  However, given Excel 2010's 64000 limit of different format combinations per spreadsheet, I know I am not hitting that limit, but yet if I try to apply new format/comments, I either trigger the error I noted above or Excel will crash.  Therefore, I think my spreadsheet is internally corrupt somehow.  

Does anyone know of a way to count the number of format combinations currently in use?  I have tried to google that, but closest I got was the number of styles in use, but that number is only 2 in the spreadsheet.

Thoughts?  Or is there a way to re-save the spreadsheet in a different format which can help fix the potential corruption?

Much appreciate everyone trying to help me!
How is a typical comment of your formatted?
Avatar of Hammer8

ASKER

Hi, not sure what you mean by a comment being formatted.  I would say they are not formatted.  I just use:   cell.addcomment "text"

to add a comment.
What do you mean by
I try to apply new format/comments
Avatar of Hammer8

ASKER

I mean the code I have will format certain cell (eg., set cell a certain color, change font size etc) or add comments to them depending on a set of criteria.  The code works since it loops properly until a certain point at which I will either get an error 91 (as described on opening post) or Excel will crash.
Can you attach the problem workbook or a dummy one that exhibits the same problem, and explain how to reproduce the problem?
Avatar of Hammer8

ASKER

I cannot since the spreadsheet is huge and also won't open unless some addins etc are in place...

Is there a way to know how many format combo's are currently in use by the spreadsheet.  I know I can alway try to re-create it from scratch to remove the internal corruption, but that will be a very time consuming process.

Anyway to re-save it as another format or other ideas?
How about a version that doesn't include the add-ins and while it's understood that that would remove some functionality, still exhibits the error?

Could the error be coming from one of the add-ins? You could try disabling them one at a time and see if disabling one of them eliminates the error. Other than saving the sheet as a CSV file and reloading in a new workbook which might mess up what you have, I'm out of ideas.
Avatar of Hammer8

ASKER

I don't have any addins except for Bloomberg which I need.

Hi, still hoping for a solution to this...any thoughts?
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial