开发者

VBA: copy paste ranges from array

I have an array that contains the cell locations form a search function. I would like to display the results of each location in the array along with the subsequent data entry from columns D:P. Is there an efficient way of doing this? This is what I have so far but it is not a working code and i would prefer it if it only selected D:P columns instead of an entire row

Dim i1 As Integer
Dim Results1() As Variant
Dim p1results As Range
Dim NextRow as Long

   For i1 = LBound(Results1) To UBound(Results1)
     开发者_如何学JAVA   Set p1results = Results1(i1).Value
        p1results.EntireRow.Copy
        Sheets("SearchResult").Select
        NextRow = Range("D65536").End(xlUp).Row + 1
        Cells(NextRow, 1).Select
        ActiveSheet.Paste
    Next i1


Dim i1 As Integer
Dim Results1() As Variant
Dim rngDest as Range

Set rngDest = Sheets("SearchResult").Cells(rows.count,4).End(xlUp).Offset(1,-3)

For i1 = LBound(Results1) To UBound(Results1)
        
  Range(Results1(i1)).EntireRow.Copy rngDest
  Set rngDest = rngDest.Offset(1,0)
               
Next i1


For columns (D:P) Try:

Dim i1 As Integer
Dim Results1() As Variant

For i1 = LBound(Results1) To UBound(Results1)
    Sheets("SearchResult").Cells(Rows.Count, "D").End(xlUp)(2).Resize(, 13).Value = _
    Range(Results1(i1)).Resize(, 13).Value
Next i1

Assuming use dont need formats then its better to avoid using copy. Copy makes use of the clipboard which is slow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜