VBA的新手,但确实需要此代码的帮助。
因此,如果它们的名称在我的命名范围内(在Lookuptab表中,则我想复制Worksheet1的L列中的任何单元格。
到目前为止,已经有用于复制和粘贴的代码,并且工作正常,但是由于输入了countif条件,因此出现错误“未定义编译错误子函数”
请帮助!
谢谢,
我的代码如下:
a = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To a
If CountIf(Sheets("Lookup").Range("Vendor_Lookup"), Sheets("Sheet1").Cells(i, 12).Value) > 0 Then
Worksheets("Sheet1").Rows(i).Copy
Worksheets("Sheet2").Activate
b = Worksheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet2").Cells(b + 1, 1).Select
ActiveSheet.Paste
Worksheets("Sheet1").Activate
End If
Next
Application.CutCopyMode = False
End Sub
CountIf
不是VBA固有的。您必须通过
Application.WorksheetFunction.CountIf(......
另外一些注意事项:
Activate
不需要this post任何内容Union
收集目标行CountIf
,您可以使用Range.Find
保留本机VBA功能