将日期复制到另一张纸上

时间:2020-04-01 18:46:10

标签: excel vba

我有以下代码,可以根据某些过滤器将数据从一张纸复制到另一张纸上。

I列是一个基于公式Column I = A列+ 10天的日期。 我的宏将列In复制到新工作表的F列中。我希望以与日期相同的格式复制日期。例如,如果列A为4/1/2020,则列I将显示4/11/2020。我希望宏以相同的方式复制并将4/11/2020粘贴到F列。


    With sourceSheet

        ' Get last row
         lastRow = .Range("J" & .Rows.Count).End(xlUp).Row


        .Range("A1:Q1").AutoFilter Field:=14, Criteria1:="PENDING"
        .Range("A1:Q1").AutoFilter Field:=10, Criteria1:="USA"    ', Operator:=xlOr, Criteria2:="CANADA"
        .Range("A1:Q1").AutoFilter Field:=2, Criteria1:="USA"     ', Operator:=xlOr, Criteria2:="CANADA"

        .Range("K2:K" & lastRow).SpecialCells(xlCellTypeVisible).Copy _
                                     Destination:=targetSheet.Range("G2")
        .Range("C2:C" & lastRow).SpecialCells(xlCellTypeVisible).Copy _
                                     Destination:=targetSheet.Range("A2")
        .Range("E2:E" & lastRow).SpecialCells(xlCellTypeVisible).Copy _
                                     Destination:=targetSheet.Range("B2")
        .Range("G2:G" & lastRow).SpecialCells(xlCellTypeVisible).Copy _
                                     Destination:=targetSheet.Range("C2")
        .Range("I2:I" & lastRow).SpecialCells(xlCellTypeVisible).Copy _
                                     Destination:=targetSheet.Range("F2")



    End With

1 个答案:

答案 0 :(得分:0)

请使用以下内容。

{{1}}