用于循环通过命名区域单元格名称

这是场景:

如果选中了一个checkbox(SamePObx),我想遍历一个已命名的范围,并validation单元格中至less存在一个值,但包含值的单元格不能命名为“PO_Cmt”。 如果所有的单元格都是空白的,则popup一个msgbox。

If Sheet1.SamePObx.Value = True Then 'if checkbox is selected For Each cell In Sheet1.Range("SamePO") 'if the cell is blank and isn't name PO_Cmt If (cell.Value <> "") And (cell.Name <> "PO_Cmt") Then x = x + 1 'one PO is present Exit For End If Next cell 'if no POs present, flag If x = 0 Then MsgBox "Please provide the necessary PO#(s)" GoTo cont End If 

我遇到的问题是1004的运行时错误。这条线是问题:

 If (cell.Value <> "") And (cell.Name <> "PO_Cmt") Then 

 If Sheet1.SamePObx.Value = True Then 'if checkbox is selected x = Application.CountA(Sheet1.Range("SamePO")) If Range("PO_Cmt").Value <> "" Then x = x - 1 'if no POs present, flag If x = 0 Then MsgBox "Please provide the necessary PO#(s)" GoTo cont End If End If