将字符串变量设置为单元格-应用程序定义或对象定义的错误

时间:2019-03-10 19:43:58

标签: excel vba

我已经尝试了所有发现的东西,没有运气就想到了。

我有一小段代码,这些代码根据已定义的设置范围为我写了一个摘要。

问题是将sumifs写入变量后,我无法将该变量输出到单元格或范围。我不断收到“应用程序定义或对象定义”错误。

有问题的代码行:

spr = a

我不认为定义的输出范围是问题所在,因为我能够输出一个字母(输入进行测试),但是当我尝试输出该变量时,它不起作用,并一直给我“ application-定义或对象定义的错误。

请帮助!

完整代码:

Sub create_SPAAT_Data()

Dim difs As Integer
Dim dife As Integer
Dim sps As Integer
Dim spe As Integer
Dim ros As Integer
Dim roe As Integer
Dim spr As Range

Set ro = Worksheets("RO_History_Processed")
Set sp = Worksheets("Shipment Processed")
Set sku = Worksheets("skus")
Set spa = Worksheets("SPAAT")
Set spr = spa.Range("O211")

' find start and end rows for differene, sp and ro in SPAAT front end
lrow = sku.Cells(Rows.Count, 1).End(xlUp).Row
difs = 5
dife = difs + (lrow - 1)
sps = dife + 1
spe = sps + ((lrow * 2) - 1)
ros = spe + 1
roe = ros + (lrow - 1)

' Calculate sp
    lrow2 = sp.Cells(Rows.Count, 2).End(xlUp).Row
    a = "=SUMIFS('Shipment Processed'!$C$1:$C$lrow2,'Shipment Processed'!$A$1:$A$lrow2,'SPAAT'!$Asps,'Shipment Processed'!$AB$1:$AB$lrow2,'SPAAT'!O$2,'Shipment Processed'!$AC$1:$AC$lrow2,'SPAAT'!O$4,'Shipment Processed'!$Z$1:$Z$lrow2,'SPAAT'!$Isps))"
        a = Replace(a, "lrow2", lrow2)
        a = Replace(a, "sps", sps)
    spr = a

End Sub

0 个答案:

没有答案