I am running Excel 2016 on Windows 10 Enterprise and am getting an error when I try to set the value or formatting of a cell (or cells). The error itself (Run-time error '1004': Application-defined or object-defined error) doesn't tell me much.
Key notes:
- I get the error always on the SECOND line of code. The first works fine.
- The line of code works fine when the preceding line is "commented out" or deleted.
- I get the error whether I am calling the VBA from a command button or using a Worksheet_Change event.
- I get the error when using Cells or Range and whether setting the value or formatting.
- The code is all stored in and targeted to the same worksheet from which it is triggered.
Sample Code
Expand|Select|Wrap|Line Numbers
- Range(Cells(17, 2), Cells(22, 2)).ClearContents
- Range(Cells(14, 2), Cells(21, 2)).Font.ColorIndex = 0