VBA:从数组复制粘贴范围

时间:2011-06-24 12:34:23

标签: vba copy-paste

我有一个数组,其中包含来自搜索功能的单元格位置。我想显示数组中每个位置的结果以及来自D:P列的后续数据输入。有没有一种有效的方法呢?这是我到目前为止,但它不是一个有效的代码,我更喜欢它,如果它只选择D:P列而不是整行

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

   For i1 = LBound(Results1) To UBound(Results1)
        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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

对于列(D:P),请尝试:

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

假设使用不需要格式,那么最好避免使用副本。复制使用缓慢的剪贴板。