我试图从列F中具有特定值的一张纸上复制A列到E列。 例如,我想复制具有' X&#39的行A:E。在F列中,将它们粘贴到另一张纸上。
我有一个代码可以复制和粘贴所有具有' X'但不确定要更改的内容只能将行A复制到E。
这是我的代码。
With ws.Result.Range ("A1:F" & .Cells(.Rows.Count, "F").End(xlUp).Row
.AutoFilter Field := 6, Criteria1 := wsResult.Range("C1") ' checks row F to
see whether the number in cell C1 matches any in row F
If Application.WorksheetFunction.Subtotal(103, .Columns(1)>1 Then .
Offset(1). Resize (.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Copy
Destination:= Main.Range("A22")
答案 0 :(得分:0)
重写为,
With ws.Result.Range ("A1:F" & .Cells(.Rows.Count, "F").End(xlUp).Row)
' checks row F to see whether the number in cell C1 matches any in row F
.AutoFilter Field := 6, Criteria1 := wsResult.Range("C1")
with .resize(.rows.count-1, 5).offset(1, 0)
If cbool(Application.Subtotal(103, .Cells)) Then
.SpecialCells(xlCellTypeVisible).Copy Destination:= Main.Range("A22")
end if
end with
end with
答案 1 :(得分:0)
感谢Scott Craner的回答。正确的代码如下。 "为调整大小添加列数:调整大小(.Rows.Count - 1,5)这应该排除列F - "
With ws.Result.Range ("A1:F" & .Cells(.Rows.Count, "F").End(xlUp).Row
.AutoFilter Field := 6, Criteria1 := wsResult.Range("C1") ' checks row F to
see whether the number in cell C1 matches any in row F
If Application.WorksheetFunction.Subtotal(103, .Columns(1)>1 Then .
Offset(1). Resize (.Rows.Count - 1,5).SpecialCells(xlCellTypeVisible).Copy
Destination:= Main.Range("A22")