如果行包含单词,请从列中标识并复制所有单元格并复制到另一个工作表

时间:2017-07-31 05:41:35

标签: excel vba excel-vba

我正在尝试创建一个宏,它将从Sheet(“项目部件申请”)中连续查找4个不同的单词。完成后,它将复制该4列中的所有单元格,并将在表格(A,D,E,O)中粘贴到表格(GCC)中。 我有一部分代码,但它没有查找单词,它只是简单地将预定义的单元格移动到那些列。

如果你帮我这个,我真的很感激。

With Sheets("GCC1") 
    lastrowGCC1 = .Cells(.Rows.Count, "A").End(xlUp).Row + 1 
End With
arr1 = Array("K", "P", "Q", "AA")
arr2 = Array("A", "D", "E", "O")
For i = LBound(arr1) To UBound(arr1)
    With Sheets("Project Parts Requisitioning")
         lastrow = Application.Max(n, .Cells(.Rows.Count, arr1(i)).End(xlUp).Row)
         .Range(.Cells(n, arr1(i)), .Cells(lastrow, arr1(i))).Copy
         Sheets("GCC1").Range(arr2(i) & lastrowGCC1).PasteSpecial xlPasteValues
    End With
Next
Application.CutCopyMode = False

1 个答案:

答案 0 :(得分:1)

试试这个

Sub testso()

arr1 = Array("K", "P", "Q", "AA")
arr2 = Array("A", "D", "E", "O")

For i = 0 To 3

    Sheets("GCC").Columns(arr2(i)) = Sheets("Project Parts Requisitioning").Cells.Find(arr1(i), LookIn:=xlValues, lookat:=xlPart, MatchCase:=True).EntireColumn.Value

Next i

End Sub