简体   繁体   中英

Application defined error 1004

I am trying to compare 2 cell values and further logic is based on the values in both the cells.

My code is giving "Error 1004: Application-defined or Object-defined Error".

Below is the part where I am getting the issue

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

Change this line :

If Worksheets("QA Checklist Banners").Range("i(num)").Value = "P" And Worksheets("QA Checklist Banners").Range("j(num)").Value = "F" Then

by this line:

If Worksheets("QA Checklist Banners").Range("I" & num).Value = "P" And Worksheets("QA Checklist Banners").Range("J" & num).Value = "F" Then

Finally I got the output as required by modifying my code

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM