我正在尝试比较2个单元格值,而进一步的逻辑基于两个单元格中的值。
我的代码给出了“错误1004:应用程序定义或对象定义的错误”。
以下是我遇到问题的部分
Pass = Application.WorksheetFunction.CountIf(Range("i20:i256"), "P")
Fail = Application.WorksheetFunction.CountIf(Range("j20:j256"), "F")
Temp1 = (Pass + Fail)
For num = 20 To 256
If Worksheets("QA Checklist Banners").Range("i(num)").Value = "P" And _
Worksheets("QA Checklist Banners").Range("j(num)").Value = "F" Then
MsgBox ("Both column cannot contain values")
End If
Next num
答案 0 :(得分:1)
更改此行:
If Worksheets("QA Checklist Banners").Range("i(num)").Value = "P" And Worksheets("QA Checklist Banners").Range("j(num)").Value = "F" Then
这一行:
If Worksheets("QA Checklist Banners").Range("I" & num).Value = "P" And Worksheets("QA Checklist Banners").Range("J" & num).Value = "F" Then
答案 1 :(得分:0)
最后,我根据需要修改了我的代码
For Num = 20 To 256
If Sheets("QA Checklist Banners").Cells(Num, 9) = "P" And Sheets("QA Checklist Banners").Cells(Num, 10) = "F" Then
Sheets("QA Checklist Banners").Cells(Num, 9).Interior.ColorIndex = 3
Sheets("QA Checklist Banners").Cells(Num, 10).Interior.ColorIndex = 3
MsgBox ("Both column cannot contain values")
End If
Next Num