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
答案 0 :(得分:2)
错误的原因是cellStart
是Range
。
因此,您需要Set
使用:
Set cellStart = ThisWorkbook.Worksheets("OtherSheet").Cells(3, col)
注意:您最后有一个“额外”结束括号,您有2 ))
而非)