Excel - 仅使用整数获取范围的问题

Excel - Issue with using only ints to get range

    Dim cell As Range
    Dim agentRange As Range

    Set agentRange = ThisWorkbook.Worksheets("OtherSheet").Range(Range("S9").value, Range("T9").value)

    For Each cell In agentRange

        Dim col As Long
        col = cell.column

        Dim cellStart As Range
        ***cellStart = ThisWorkbook.Worksheets("OtherSheet").Cells(3, col))***

       'Do Stuff

    Next cell

我的 cellStart 分配有问题。当我尝试使用所写的代码时,我收到了一个错误。

Run-time error '91'

Object Variable or With block variable not set

错误的原因是cellStart是一个Range

因此,您需要Set它:

Set cellStart = ThisWorkbook.Worksheets("OtherSheet").Cells(3, col)

注意:最后有一个 "extra" 右括号,你有 2 个 )) 而不是 )