要复制cols并附加到其他cols下方的宏,但需要搜索:" xlWhole"有:" xlPart"

时间:2014-04-06 01:30:02

标签: excel-vba vba excel

我终于让这个工作了,但是它搜索xlPart时遇到了最后一个问题,我需要它来搜索xlWhole,但我无法确定添加xlWhole的位置

由于

Sub MoveUnder()
Dim ar As Variant
Dim er As Variant
Dim i As Variant
Dim j As Long
Dim k As Long
Dim LR As Long


Sheets("XXX").Select

    ar = Array("Target", "Label")     ' Find column to copy
    er = Array("Source", "user name") ' Find column to paste beneath


LR = Range("A" & Rows.Count).End(xlUp).Row
On Error Resume Next
   For i = LBound(ar) To UBound(ar)
       j = Rows(1).Find(ar(i)).Column
       k = Rows(1).Find(er(i)).Column

         Range(Cells(2, j), Cells(LR, j)).Copy _
           Destination:=Range(Cells(LR, k), Cells(LR, k)).Offset(1, 0)
   Next i
On Error GoTo 0
End Sub

1 个答案:

答案 0 :(得分:1)

试试这个:

j = Rows(1).Find(ar(i), Rows(1).Cells(Rows(1).Cells.Count), , xlWhole, xlByRows).Column
k = Rows(1).Find(er(i), Rows(1).Cells(Rows(1).Cells.Count), , xlWhole, xlByRows).Column

我还添加了AfterSearchOrder参数 这将从第1个条目(即单元格A1)开始搜索第1行。