我终于让这个工作了,但是它搜索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
答案 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
我还添加了After
和SearchOrder
参数
这将从第1个条目(即单元格A1)开始搜索第1行。