Search code examples
excelvbachartsexcel-2010

Excel 2010 ClearComments deleting Chart Object


I've run across a rather weird bug, which I'm able to reproduce every time. At least I'm assuming it's a bug. If I call Cell.ClearComments while a chart has focus, then that chart gets removed.

The way I'm testing this is by selecting a value from a dropdown list box, which triggers the worksheets Worksheet_Change event. It's important to note here that the selection of a value from the drop down box does not remove focus from the chart if you don't select the cell first, but just the arrow that brings down the list. Inside the event, if any cells ClearComments gets called, the chart that has focus gets deleted.

Has anyone else run across this?

Thanks, Matt

Edit:

Here's the vba code I'm using to reproduce it. It's the only code used. Make sure Events are enabled.

Private Sub Worksheet_Change(ByVal Target As Range)
    Worksheets("Sheet1").Cells(1, 4).ClearComments
End Sub

Here's hopefully a more clear list of steps taken to reproduce.

  1. Create values in cells A1:A4
  2. In B1, create a Data Validation dropdown list using previously created values
  3. Create a chart object, it doesn't have to have any data tied to it.
  4. Click on the cell with dropdown to get dropdown arrow to show up.
  5. Click on chart object to give it focus.
  6. Click "only" on the dropdown arrow, the list should show up, but the chart shouldn't lose focus.
  7. Click on a value from the list. This will trigger the event and cause the ClearComments to run.
  8. Chart should disappear. It does for me at least.

Solution

  • To get around this bug I activated a Cell on the Worksheet before calling ClearComments. This removed focus from the chart and prevented it from being destroyed.