views:

45

answers:

1

This one has me stumped. When I set the formula for a selected cell in a ListObject, if the ListColumn is empty, Excel fills the formula for the whole column, rather than just the Selection. I have duplicated this in a separate workbook.

  1. Create a Table
  2. Insert a five or so rows
  3. Click on (select) one of the cells in the column
  4. Execute the following code:

    Sub setCellFormula() Selection.Formula = "=myFormula()" End Sub

    Function myFormula() As Integer myFormula = 1 End Function

  5. Note that the whole column is filled with the numeral one

  6. Delete the data in the cells
  7. Enter any value in any of the cells
  8. Select a cell other than the cell with a value in it
  9. Re-execute step 4
  10. Note that only the selected cell is filled with the numeral one
+1  A: 

My experience is that, irregardless of VBA, Tables behave as you have described in XL 2007, and Lists behave as you'd prefer in XL 2003. However in 2007 you can tell it to "stop creating calculated columns." So I'd guess it's not a code issue, but an issue due to different behavior between versions, or different settings for two instances of XL 2007.

Doug Glancy
This is right idea. A reply in another forum gave a few more details that clued me in on the the issue. Click the Office Button --> Proofing --> AutoCorrect Options --> the "AutoFormat As You Type" tab. There is a "Fill formulas in tables to create calculated columns" option. If this option is enabled and you enter a formula in a single cell of an empty column, Excel will fill the entire column with the formula. A decent article describing this behavior and options in dealing with it is located at: http://www.worldstart.com/tips/tips.php/5260
Adam