VBA:从数组复制粘贴范围

发布于 2024-11-17 03:54:47 字数 524 浏览 1 评论 0原文

我有一个数组,其中包含搜索函数中的单元格位置。我想显示数组中每个位置的结果以及 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

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)
        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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

私野 2024-11-24 03:54:47
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
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
风筝在阴天搁浅。 2024-11-24 03:54:47

对于列 (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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文