我有ID&的数据值和我有这个宏运行我的功能,粘贴在电子表格中的公式。我的数据采用衰落曲线分析的形式。基本上,我要问的是,当我的ID列发生变化而不是仅仅粘贴所有数据(6)时,我是否可以修改我的代码以重新启动数据(0)。
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
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(6)
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[-15]:R[-5]C[-15])+(RC[-15]*SLOPE(RC[-11]:R[5]C[-11],RC[-15]:R[5]C[-15])))-RC[-11]", "=IF(RC[-11]=0,0,IF(RC[-1]>RC[-11],0,1))", "=IF(RC[-1]=1,RC[-11],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],R[-1]C[-15]:R[4]C[-15])+(RC[-15]*SLOPE(R[-1]C[-11]:R[4]C[-11],R[-1]C[-15]:R[4]C[-15])))-RC[-11]", "=IF(RC[-11]=0,0,IF(RC[-1]>RC[-11],0,1))", "=IF(RC[-1]=1,RC[-11],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],R[-2]C[-15]:R[3]C[-15])+(RC[-15]*SLOPE(R[-2]C[-11]:R[3]C[-11],R[-2]C[-15]:R[3]C[-15])))-RC[-11]", "=IF(RC[-11]=0,0,IF(RC[-1]>RC[-11],0,1))", "=IF(RC[-1]=1,RC[-11],0)", "=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],R[-3]C[-15]:R[2]C[-15])+(RC[-15]*SLOPE(R[-3]C[-11]:R[2]C[-11],R[-3]C[-15]:R[2]C[-15])))-RC[-11]", "=IF(RC[-11]=0,0,IF(RC[-1]>RC[-11],0,1))", "=IF(RC[-1]=1,RC[-11],0)", "=0", "=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)", "=(INTERCEPT(R[-3]C[-11]:R[2]C[-11],R[-3]C[-15]:R[2]C[-15])+(RC[-15]*SLOPE(R[-3]C[-11]:R[2]C[-11],R[-3]C[-15]:R[2]C[-15])))-RC[-11]", "=IF(RC[-11]=0,0,IF(RC[-1]>RC[-11],0,1))", "=IF(RC[-1]=1,RC[-11],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)", "=(INTERCEPT(R[-3]C[-11]:R[2]C[-11],R[-3]C[-15]:R[2]C[-15])+(RC[-15]*SLOPE(R[-3]C[-11]:R[2]C[-11],R[-3]C[-15]:R[2]C[-15])))-RC[-11]", "=IF(RC[-11]=0,0,IF(RC[-1]>RC[-11],0,1))", "=IF(RC[-1]=1,RC[-11],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)", "=(INTERCEPT(R[-3]C[-11]:R[2]C[-11],R[-3]C[-15]:R[2]C[-15])+(RC[-15]*SLOPE(R[-3]C[-11]:R[2]C[-11],R[-3]C[-15]:R[2]C[-15])))-RC[-11]", "=IF(RC[-11]=0,0,IF(RC[-1]>RC[-11],0,1))", "=IF(RC[-1]=1,RC[-11],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