如何将部分VBA阵列粘贴到excel范围 [英] how to paste part of VBA array to excel range

查看:66
本文介绍了如何将部分VBA阵列粘贴到excel范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过某种方式将vba数组的一部分粘贴到Excel范围内?

Is it somehow possible to past part of an vba array to an excel range?

我需要做这样的事情:

dim testday() as Variant
testday = Sheets("raw").Range("E745:BN745").Value
Sheets("raw").Range("E745:BN745").Value = ""
Sheets("Interface").Range("B4:E4") = testday(3, 4, 5, 6).Value

但是这不起作用...有办法解决这个问题吗?谢谢!

but this doesn't work... is there a way to fix this? Thx!

推荐答案

您可以:

  • 使用循环将所需的值复制到新数组,并将其写入您的范围.如果您打算经常执行此操作,则可以编写一个可重用的函数来执行此操作.或者,

  • Use a loop to copy the values you need to a new array, and write that to your range. If you're going to do this often, you can write a reusable function that does this. Or,

仅从原始" 表中读取所需内容,然后将其写入您的范围,如下所示.在您的特定情况下,这可能是最简单的解决方案.

Read only what you need from your "raw" sheet, and write that to your range, as illustrated below. This is probably the simplest solution in your particular case.


Dim testday() As Variant
testday = Sheets("raw").Range("G745:J745").Value ' only read what you need
Sheets("raw").Range("E745:BN745").ClearContents
Sheets("Interface").Range("B4:E4") = testday(3, 4, 5, 6).Value

这篇关于如何将部分VBA阵列粘贴到excel范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆