2011-04-21 56 views
0

我試圖複製在兩個值是空白,第三單元格的值是MS-NORT
我的代碼是下面,但我得到一個語法錯誤整個行。基於多種細胞複製整個行的值

請幫助

Set MK = Sheets("data dump").Range("P1:Q5000") 
For Each cell In MK 

If cell.Value = "" And Sheets("Data Dump").Range("M1:M5000") <> "MS-NORT" 
Then cell.EntireRow.copy 
Sheets("working data").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial 
End If 
Application.CutCopyMode = False 
Next 
+0

語法錯誤,其中行具體嗎? – Johan 2011-04-21 09:11:02

+0

如果cell.Value =「」和表(「數據轉儲」)。範圍(「M1:M5000」)<>「MS-NORT」 – SteveW1968 2011-04-21 09:24:12

+0

更新了答案,看看。 – Johan 2011-04-21 09:53:52

回答

1

我不太清楚你的意思「其中兩個值是空白,第三單元格的值是MS-NORT」

我假設你想檢查每一行,如果列M <>「MS-NORT」並且列P和Q都爲空,則複製該行。此代碼將這樣做

Sub test() 
Dim rngRow As Range, MK As Range, lngrow As Long 
Dim varCheckCol1 As Variant, varCheckCol2 As Variant, varCheckCol3 As Variant 

Set MK = Sheets("data dump").Range("M1:Q5000") 
For Each rngRow In MK.Rows 

    varCheckCol1 = rngRow.Value2(1, 1) 'col M 
    varCheckCol2 = rngRow.Value2(1, 4) 'col P 
    varCheckCol3 = rngRow.Value2(1, 5) 'col Q 

    If IsEmpty(varCheckCol2) And IsEmpty(varCheckCol3) And varCheckCol1 <> "MS-NORT" Then 
    rngRow.EntireRow.Copy 
    Sheets("working data").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial 
    End If 

Next 

End Sub