Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Error message when you use the Range.Calculate method to calculate formulas in an Excel workbook: "Run-time error '1004'"


View products that this article applies to.

Symptoms

When you use the Range.Calculate method to calculate formulas in a Microsoft Excel workbook, you may receive the following error message:
Run-time error '1004':

Calculate method of Range class failed

↑ Back to the top


Cause

This behavior may occur if the range that you are trying to calculate contains only part of an array range.

↑ Back to the top


Workaround

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To work around this behavior, calculate the entire array range. To do this, use the following Microsoft Visual Basic for Applications (VBA) macro code:
Sub CalcTheRange()

   'Replace Cell with the actual cell range in your workbook
   'For example, ("A2:F4")
   SafeCalcRange ThisWorkbook.Sheets("SheetName").Range("Cell:Cell")

End Sub
 

Sub SafeCalcRange(rng As Range)

   For Each cl In rng.Cells

      If cl.HasArray Then Set rng = Union(rng, cl.CurrentArray)

   Next cl

   rng.Calculate

End Sub

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


More information

This behavior is consistent with user interface behavior because you cannot change part of an array range.

For more information about a design change in Excel for formula calculations, click the following article number to view the article in the Microsoft Knowledge Base:
825012� How formula calculations are performed in Excel 2002 or Excel 2003

↑ Back to the top


Keywords: KB825011, kbprb, kberrmsg, kbnofix

↑ Back to the top

Article Info
Article ID : 825011
Revision : 6
Created on : 11/20/2006
Published on : 11/20/2006
Exists online : False
Views : 344