当使用对于范围中的每个单元格时,我想使用 cell.row 属性来引用当前单元格的行。但是,如果我在另一个Sub中使用它,我会收到错误运行时错误:' 424'需要对象。
下面是一个简单的代码来说明我的意思。我做错了什么或有没有办法在另一个Sub中引用当前单元格的行?谢谢!
Sub CommandButton2_Click()
Dim rng As Range
Set rng = Range("P290:P293")
For Each cell In rng
Third
Next cell
End Sub
Sub Third()
MsgBox cell.row
End Sub
答案 0 :(得分:2)
Sub CommandButton2_Click()
Dim rng As Range, cell As Range
Set rng = Range("P290:P293")
For Each cell In rng
Third cell
Next cell
End Sub
Sub Third(cell As Range)
MsgBox cell.row
End Sub
您需要将其作为参数传递。