如何复制 select 列,其中所有行在 A 列中具有特定编号

How to copy a select amount of columns with all rows that have a specific number in column A

我正在尝试从 F 列中具有特定值的 sheet 复制 A 列到 E 列。 例如,我想复制 F 列中具有 'X' 的行 A:E,并将它们粘贴到另一个 sheet。

我有一个代码可以复制和粘贴具有 '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") 

重写为,

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

感谢 Scott Craner 的回答。正确的代码如下。 "add a column count to the resize: Resize (.Rows.Count - 1,5) This should exclude column 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")