Avatar of Hammer8
Hammer8
Flag 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
Microsoft ExcelMicrosoft Development

Avatar of undefined
Last Comment
Martin Liss

8/22/2022 - Mon
theruck

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
Martin Liss

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

Martin Liss

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

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Ryan

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.
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!
Martin Liss

How is a typical comment of your formatted?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
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.
Martin Liss

What do you mean by
I try to apply new format/comments
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.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Martin Liss

Can you attach the problem workbook or a dummy one that exhibits the same problem, and explain how to reproduce the problem?
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?
Martin Liss

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
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
Martin Liss

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.