简体   繁体   中英

Attempting copy paste cells from one sheet to another?

I am attempting to copy column B from sheet called "Activity Overview" (Only filled cells) and paste in a sheet called "V&VFile" in column E from row 11 onwards, however when i run the macro the cells arent copied and seems to paste blank cells.

The source of the data uses excel formula index match, is this why as it can copy the data as its found from an excel formula?

Sub VVfileFILL()

Dim Lastrow As Double

Lastrow = Worksheets("Activity Overview").Cells(Rows.Count, "B").End(xlUp).Row

ThisWorkbook.Worksheets("Activity Overview").Range("B" & Lastrow).Copy

ThisWorkbook.Sheets("V&V").Range("E" & Rows.Count).End(xlUp).Offset(10, 0).PasteSpecial xlPasteValues

End Sub

Don't think one can avoid a loop in this situation.

Sub VVfileFILL()

Dim Lastrow As Long, r As Long, n As Long

n = Worksheets("V&V").Range("E" & Rows.Count).End(xlUp).Offset(10, 0).Row

With Worksheets("Activity Overview")
    Lastrow = .Cells(Rows.Count, "B").End(xlUp).Row
    For r = 2 To Lastrow
        If Len(.Cells(r, "B")) > 0 Then 'check not blank
            If WorksheetFunction.CountIf(Worksheets("V&V").Range("E1:E" & n), .Cells(r, "B")) = 0 Then 'check not already in E
                Worksheets("V&V").Cells(n, "E").Value = .Cells(r, "B").Value 'transfer value
                n = n + 1 'add 1 to destination row
            End If
        End If
    Next r
End With

End Sub

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