无法设置两个工作表的范围 VBA

Can’t set range from two worksheets VBA

我不明白为什么我总是收到“应用程序定义或对象定义的错误”。我已尝试将代码移至单独的模块,并仔细检查了工作表名称。

Sub CreateCalculations()
Set SummTrans = Worksheets(“Summary”).Range(“I3”, Range(“I3”).End(xlDown))
Set RegTrans = Worksheets(“Register”).Range(“A3”, Range(“A3”).End(xlDown))
End Sub

出于某种原因,这段代码确实有效,但它不是我需要的。

Sub CreateCalculations()
Set SummTrans = Worksheets(“Summary”).Range(“I3”, Range(“I3”).End(xlDown))
Set RegTrans = Worksheets(“Register”).Range(“A3”)
End Sub

试试,

Sub CreateCalculations()
    Dim SummTrans As Range
    Dim RegTrans As Range
    
    With Worksheets("Summary")
        Set SummTrans = .Range("I3", .Range("I3").End(xlDown))
    End With
    With Worksheets("Register")
        Set RegTrans = .Range("A3", .Range("A3").End(xlDown))
    End With
End Sub