我正在尝试复制整行,其中两个值为空,第三个单元格值为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 :(得分:1)
我不确定你的意思是“两个值为空,第三个单元格值为MS-NORT”
我假设你要检查每一行,如果列M&lt;&gt; “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