VBA:对于wRange中的每个wCell

我遇到For Each循环的问题。

我试图使用循环:

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 

当我将variables定义为:

 Dim wRange As Range Dim wCell As Range 

我得到一个运行时错误的Object variable or With block variable not set在行上

wRange = Range(Cells(5, countryCol), Cells(lastrow, countryCol))

当我将variables定义为:

Dim wRange, wCell As Range

我得到一个运行时错误:线上Object requiredObject 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"

正如对原始问题的评论所述,我需要使用Set

 Set wRange = Range(Cells(5, countryCol), Cells(lastrow, countryCol)) For Each wCell In wRange If wCell = "Unknown" Or wCell = "" Then wCell.Offset(0, reviewStatus - countryCol).Value = "Follow up with receiving" wCell.Offset(0, followUp - countryCol) = "Send to receiving" End If Next