简体   繁体   中英

Copy date into another sheet

I have the below code to copy data from one sheet to another based on some filters.

The Column I is a date which is based on the formula Column I = Column A + 10 days. My Macro copies Column In to Column F of new sheet.I want the date to copied in the same format as it is there. For eg if Column A is 4/1/2020 then Column I will be showing 4/11/2020 . I want the Macro to copy the same way and paste 4/11/2020 to the column 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

Please use the below..

.Range("I2:I" & lastRow).SpecialCells(xlCellTypeVisible).Copy
         targetSheet.Range("F2").PasteSpecial Paste:=xlPasteValuesAndNumberFormats

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM