2013-07-02 72 views
0

我正在運行下面的代碼,如果單元格值包含在列號中,我將刪除行。 15未激活,列10中的單元格值不是「e & d」,「vpg」等。它返回我這個錯誤:'運行時錯誤13類型不匹配'。運行時錯誤13類型不匹配

現在,當我爲單個條件運行它時,它適用於例如單元格值=活動或單元格值= E & D,但添加多個條件會返回錯誤。語法錯了嗎?我甚至嘗試過切換,而不是'或',把條件放在括號內,用逗號分隔它們。由於顯而易見的原因,由於語法問題,它不起作用。任何人都可以善意指出我的錯誤嗎?

Sub test() 
Dim n1, n2, x, z, lastrow As Variant 



        ' To delete entire row if criteria is not met 
        Worksheets("Sheet2").Activate 
        Range("A4").Select 
        lastrow = Cells(Rows.Count, 1).End(xlUp).Row 
        For x = lastrow To 4 Step -1 
         If Cells(x, 15).Value <> "Active" And (Cells(x, 10).Value <> "E&D" Or "ESG" Or "DLM SER" Or "VPD" Or "PLM PROD") Then 
         Rows(x).Delete 
         End If 
        Next x 
End Sub 

在此先感謝!

回答

0

你的if語句的語法是錯誤的,你需要多次specity的左側這樣

If Cells(x, 15).Value <> "Active" And (Cells(x, 10).Value <> "E&D" And Cells(x, 10).Value <> "ESG" And Cells(x, 10).Value <> "DLM SER" And Cells(x, 10).Value <> "VPD" And Cells(x, 10).Value <> "PLM PROD") Then 

您還需要而不是,或因爲要檢查所有的這種情況下使用,如果你想刪除或者不主動或在列10的值不匹配行的條件爲真,即沒有列出的值都在小區X,10

編輯

喲ü可能要使用以下

If Cells(x, 15).Value <> "Active" Or (Cells(x, 10).Value <> "E&D" And Cells(x, 10).Value <> "ESG" And Cells(x, 10).Value <> "DLM SER" And Cells(x, 10).Value <> "VPD" And Cells(x, 10).Value <> "PLM PROD") Then 

公告的或兩個主要條件

+0

它沒有工作的伴侶之間,是錯誤消失的說法是不檢查 – mathew

+0

編輯我的答案 – gareththegeek

+0

感謝加雷斯條件但我想刪除行 首先如果不活躍,那麼如果不符合值是「或」的路要走? 顯然這是感謝gareth – mathew

相關問題