2
我遇到For Each問題。VBA:對於wRange中的每個wCell
我試圖使用循環:
wRange = Range(Cells(5, countryCol), Cells(lastrow, countryCol))
For Each wCell In wRange
If wCell = "Unknown" Then
wCell.Offset(0, 3).Value = "Follow up with receiving"
wCell.Offset(0, followUp - countryCol) = "Send to receiving"
End If
Next
當我定義變量爲:
Dim wRange As Range
Dim wCell As Range
我得到一個運行時錯誤Object variable or With block variable not set
上線
wRange = Range(Cells(5, countryCol), Cells(lastrow, countryCol))
當我將變量定義爲:
Dim wRange, wCell As Range
我得到一個運行時錯誤:Object required
上線
For Each wCell In wRange
如果我使用像
For Each cell In wRange
If cell = "Unknown" Then
cell.Offset(0, 3).Value = "Follow up with receiving"
cell.Offset(0, followUp - countryCol) = "Send to receiving"
End If
Next
環路我得到一個運行時間錯誤Object required
就行
cell.Offset(0, 3).Value = "Follow up with receiving"
可能需要限定的範圍內。 – findwindow
您需要使用'Set':'Set wRange = Range(Cells(5,countryCol),Cells(lastrow,countryCol))' – Rory
正如@Rory所說的,每次你只需要使用'Set'關鍵字爲對象變量賦值。 – R3uK