使用Array运行时错误1004

时间:2017-05-15 17:06:44

标签: vba excel-vba excel

当我收到此错误时,我无法找到类似于我正在尝试的内容,所以我想发布正在发生的事情。我正在尝试粘贴我的公式数组,但我不断收到错误,“运行时错误1004:应用程序定义或对象定义错误”。下面是Macro,然后是下面的两个函数。我的错误出现在宏中,有一行,“Target.FormulaR1C1 = FormulaR1C1”从我读过的内容来看,我觉得这只是一个引用错误,但我不确定。

Sub Quick()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim Target As Range
Dim lastRow As Long
Dim FormulaR1C1

FormulaR1C1 = getR1C1Array
Set Target = Range("A1:ZZ1").Find("LiquidD")

If Not Target Is Nothing Then
    lastRow = Cells(Rows.Count, 1).End(xlUp).Row
    Set Target = Target.Offset(1).Resize(UBound(FormulaR1C1, 1), UBound(FormulaR1C1, 2))
    Target.FormulaR1C1 = FormulaR1C1                                'Error 1004 Occurs
    Set Target = Target.Rows(Target.Rows.Count).Resize(lastRow - Target.Rows.Count)
    Target.Rows(1).AutoFill Destination:=Target
    'Uncomment to replace worksheet formulas with their value for better performance
    'Target.EntireColumn.Value = Target.EntireColumn.Value
End If

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

Function getR1C1Array()
Dim data
ReDim data(11)

data(0) = Array("=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]", "=RC[-3]+RC[-2]/6", "=RC[-4]+RC[-3]/14", "=IF(AND(R[1048574]C[-18]=RC[-18],COUNTIF(RC[9]:R[1048574]C[-9],0)=0),AVERAGE(RC[-9]:R[1048574]C[-9]),0)", "=IF(AND(R[1048574]C[-19]=RC[-19], COUNTIF(RC[-9]:R[1048574]C[-9],0)=0),AVERAGE(RC[-9]:R[1048574]C[-9]),0)", "=IF(AND(R[1048574]C[-20]=RC[-20],COUNTIF(RC[-9]:R[1048574]C[-9],0)=0),AVERAGE(RC[-9]:R[1048574]C[-9]),0)", "=IF(AND(R[1048571]C[-21]=RC[-21],COUNTIF(RC[-6]:R[1048571]C[-6],0)=0),AVERAGE(RC[-6]:R[1048571]C[-6]),0)", "=IF(AND(R[1048571]C[-22]=RC[-22],COUNTIF(RC[6]:R[1048571]C[6],0)=0),AVERAGE(RC[6]:R[1048571]C[6]),0)", "=IF(R[1048571]C[-23]=RC[-23],AVERAGE(RC[6]:R[1048571]C[6]),0)", "=(INTERCEPT(RC[-11]:R[5]C[-11])+(RC[-19]*SLOPE([RC[-11]:R[5]C[-11])))-RC[-11])", "=IF(RC[-12]=0,0,IF(RC[-1]>RC[-12],0,1))", "=IF(RC[-1]=1,RC[-13],0)", "=0", "=0")
data(1) = Array("=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]", "=RC[-3]+RC[-2]/6", "=RC[-4]+RC[-3]/14", "=IF(AND(R[-2]C[-18]=RC[-18],COUNTIF(R[-2]C[-9]:RC[-9],0)=0),AVERAGE(R[-2]C[-9]:RC[-9]),0)", "=IF(R[-2]C[-19]=RC[-19],AVERAGE(R[-2]C[-9]:RC[-9]),0)", "=IF(AND(R[-2]C[-20]=RC[-20],COUNTIF(R[-2]C[-9]:RC[-9],0)=0),AVERAGE(R[-2]C[-9]:RC[-9]),0)", "=IF(AND(R[1048571]C[-21]=RC[-21],COUNTIF(RC[-6]:R[1048571]C[-6],0)=0),AVERAGE(RC[-6]:R[-1048571]C[-6]),0)", "=IF(AND(R[1048571]C[-22]=RC[-22],COUNTIF(RC[-6]:R[1048571]C[-6],0)=0),AVERAGE(RC[-6]:R[1048571]C[-6]),0)", "=IF(AND(R[1048571]C[-23]=RC[-23],COUNTIF(RC[-6]:R[1048571]C[-6],0)=0),AVERAGE(RC[-6]:R[1048571]C[-6]),0)", "=(INTERCEPT(R[-1]C[-11]:R[4]C[-11])+(RC[-19]*SLOPE([R[-1]C[-11]:R[4]C[-11])))-RC[-11])", "=IF(RC[-12]=0,0,IF(RC[-1]>RC[-12],0,1))", "=IF(RC[-1]=1,RC[-13],0)", "=0", "=0")
data(2) = Array("=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]", "=RC[-3]+RC[-2]/6", "=RC[-4]+RC[-3]/14", "=IF(AND(R[-2]C[-18]=RC[-18],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(R[-2]C[-19]=RC[-19],AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-2]C[-20]=RC[-20],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[1048571]C[-21]=RC[-21],COUNTIF(RC[-6]:R[1048571]C[-6],0)=0),AVERAGE(RC[-6]:R[-1048571]C[-6]),0)", "=IF(AND(R[1048571]C[-22]=RC[-22],COUNTIF(RC[-6]:R[1048571]C[-6],0)=0),AVERAGE(RC[-6]:R[1048571]C[-6]),0)", "=IF(AND(R[1048571]C[-23]=RC[-23],COUNTIF(RC[-6]:R[1048571]C[-6],0)=0),AVERAGE(RC[-6]:R[1048571]C[-6]),0)", "=(INTERCEPT(R[-2]C[-11]:R[3]C[-11])+(RC[-19]*SLOPE([R[-2]C[-11]:R[3]C[-11])))-RC[-11])", "=IF(RC[-12]=0,0,IF(RC[-1]>RC[-12],0,1))", "=IF(RC[-1]=1,RC[-13],0)", "=IF(SUM(R[-2]C[-2]:RC[-2])=3,AVERAGE(R[-2]C[-2]:RC[-2]),0)", "=0")
data(3) = Array("=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]", "=RC[-3]+RC[-2]/6", "=RC[-4]+RC[-3]/14", "=IF(AND(R[-2]C[-18]=RC[-18],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(R[-2]C[-19]=RC[-19],AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-2]C[-20]=RC[-20],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[1048571]C[-21]=RC[-21],COUNTIF(RC[-6]:R[1048571]C[-6],0)=0),AVERAGE(RC[-6]:R[-1048571]C[-6]),0)", "=IF(AND(R[1048571]C[-22]=RC[-22],COUNTIF(RC[-6]:R[1048571]C[-6],0)=0),AVERAGE(RC[-6]:R[1048571]C[-6]),0)", "=IF(AND(R[1048571]C[-23]=RC[-23],COUNTIF(RC[-6]:R[1048571]C[-6],0)=0),AVERAGE(RC[-6]:R[1048571]C[-6]),0)", "=(INTERCEPT(R[-3]C[-11]:R[2]C[-11])+(RC[-19]*SLOPE([R[-3]C[-11]:R[2]C[-11])))-RC[-11])", "=IF(RC[-12]=0,0,IF(RC[-1]>RC[-12],0,1))", "=IF(RC[-1]=1,RC[-13],0)", "=IF(SUM(R[-2]C[-2]:RC[-2])=3,AVERAGE(R[-2]C[-2]:RC[-2]),IF(SUM(R[-3]C[-2]:RC[-2])=3,AVERAGEIF(R[-3]C[-2]:RC[-2],1,R[-3]C[-1]:RC[-1])))", "=0")
data(4) = Array("=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]", "=RC[-3]+RC[-2]/6", "=RC[-4]+RC[-3]/14", "=IF(AND(R[-2]C[-18]=RC[-18],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(R[-2]C[-19]=RC[-19],AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-2]C[-20]=RC[-20],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-5]C[-21]=RC[-21],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-22]=RC[-22],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-23]=RC[-23],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=0", "=0", "=0", "=0", "=0")
data(5) = Array("=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]", "=RC[-3]+RC[-2]/6", "=RC[-4]+RC[-3]/14", "=IF(AND(R[-2]C[-18]=RC[-18],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(R[-2]C[-19]=RC[-19],AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-2]C[-20]=RC[-20],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-5]C[-21]=RC[-21],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-22]=RC[-22],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-23]=RC[-23],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=0", "=0", "=0", "=0", "=0")
data(6) = Array("=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]", "=RC[-3]+RC[-2]/6", "=RC[-4]+RC[-3]/14", "=IF(AND(R[-2]C[-18]=RC[-18],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(R[-2]C[-19]=RC[-19],AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-2]C[-20]=RC[-20],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-5]C[-21]=RC[-21],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-22]=RC[-22],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-23]=RC[-23],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=0", "=0", "=0", "=0", "=0")
data(7) = Array("=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]", "=RC[-3]+RC[-2]/6", "=RC[-4]+RC[-3]/14", "=IF(AND(R[-2]C[-18]=RC[-18],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(R[-2]C[-19]=RC[-19],AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-2]C[-20]=RC[-20],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-5]C[-21]=RC[-21],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-22]=RC[-22],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-23]=RC[-23],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=0", "=0", "=0", "=0", "=0")
data(8) = Array("=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]", "=RC[-3]+RC[-2]/6", "=RC[-4]+RC[-3]/14", "=IF(AND(R[-2]C[-18]=RC[-18],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(R[-2]C[-19]=RC[-19],AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-2]C[-20]=RC[-20],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-5]C[-21]=RC[-21],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-22]=RC[-22],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-23]=RC[-23],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=0", "=0", "=0", "=0", "=0")
data(9) = Array("=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]", "=RC[-3]+RC[-2]/6", "=RC[-4]+RC[-3]/14", "=IF(AND(R[-2]C[-18]=RC[-18],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(R[-2]C[-19]=RC[-19],AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-2]C[-20]=RC[-20],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-5]C[-21]=RC[-21],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-22]=RC[-22],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-23]=RC[-23],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=0", "=0", "=0", "=0", "=0")
data(10) = Array("=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]", "=RC[-3]+RC[-2]/6", "=RC[-4]+RC[-3]/14", "=IF(AND(R[-2]C[-18]=RC[-18],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(R[-2]C[-19]=RC[-19],AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-2]C[-20]=RC[-20],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-5]C[-21]=RC[-21],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-22]=RC[-22],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-23]=RC[-23],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=0", "=0", "=0", "=0", "=0")
data(11) = Array("=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]/DAY(EOMONTH(RC[-2],0))", "=RC[-2]", "=RC[-3]+RC[-2]/6", "=RC[-4]+RC[-3]/14", "=IF(AND(R[-2]C[-18]=RC[-18],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(R[-2]C[-19]=RC[-19],AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-2]C[-20]=RC[-20],COUNTIF(R[-2]C[-3]:RC[-3],0)=0),AVERAGE(R[-2]C[-3]:RC[-3]),0)", "=IF(AND(R[-5]C[-21]=RC[-21],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-22]=RC[-22],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=IF(AND(R[-5]C[-23]=RC[-23],COUNTIF(R[-5]C[-6]:RC[-6],0)=0),AVERAGE(R[-5]C[-6]:RC[-6]),0)", "=0", "=0", "=0", "=0", "=0")

data = Application.Transpose(data)
data = Application.Transpose(data)
getR1C1Array = data

End Function

Function getFormulaR1C1Array(Source As Range)
Dim r As Range
Dim Result As String
Result = "Array("
For Each r In Source
    Result = Result & Chr(34) & Replace(r.FormulaR1C1, Chr(34), Chr(34) & Chr(34)) & Chr(34) & ","
Next

Result = Left(Result, Len(Result) - 1) & ")"

getFormulaR1C1Array = Result

End Function

我已经运行了很多检查,因此函数的语法应该没问题。这只是一个错误。

0 个答案:

没有答案