可以将一定范围的变体转储到工作表中吗? [英] Is it possible to dump a certain range of variant into the sheet?

查看:100
本文介绍了可以将一定范围的变体转储到工作表中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的变体

var = sheet1.Range("A1:P3600").Value

我已经做了一些操作,并将不想要的行推到了变体的顶部。现在我必须从一定的范围将var变体复制到其他工作表。

I have done some operarions and pushed the unwanted rows to the top in the variant. Now I have to copy the var variant to the other sheet from a certain range.

sheet1.range("A3444:P" & i).value = var(range(cells(r,"A").cells(l,"P"))

那就是说var(350到结束的var)应该被复制到另一个表中,可以吗?我们可以这样做吗?

that is say var(350 to end of var) should be copied to the other sheet. Is it possible ? can we do like that ?

推荐答案

一种方法是将reduce数组转储到第二个数组,然后将第二个数组转储到你的范围内

One way is to dump the reduced array to a second array, then the second array to your range

下面的代码创建一个具有3600行×16列(即A:P)的变量数组,将数据转储到数组中用于样本数据(注意,您已经将该数组作为Var),则将变量用作一个将数组减少到第二个数组的标记,然后将第二个数组写入范围。

The code below makes a variant array with 3600 rows by 16 columns (ie A:P), data is dumped into the array for sample data (note you already have this array as Var), then a variable is used as a marker to reduce the array to a second array, the second array is then written to the range.

更新以匹配您的确切数据位置。您已经有Var1(您的Var),所以您只需要从 lngStop = 350 开始的代码的第二部分,并使我的co de Var1 参考 Var

Updated to match your exact data locations. In your case you have Var1 already (your Var), so you just need the second portion of the code that starts at lngStop = 350 and make my code Var1 references Var

Sub TestME()
Dim Var1
Dim Var2
Dim lngCnt As Long
Dim lngCnt2 As Long
Dim lngCnt3 As Long
Dim lngCnt4 As Long
Dim lngStop As Long
Var1 = Sheet1.Range([a1], [p3600]).Value2
For lngCnt = 1 To UBound(Var1, 1)
    For lngCnt2 = 1 To 16
        Var1(lngCnt, lngCnt2) = "I am row " & lngCnt & " column " & lngCnt2
    Next lngCnt2
Next lngCnt
lngStop = 350
ReDim Var2(1 To UBound(Var1, 1) - lngStop + 1, 1 To UBound(Var1, 2))
For lngCnt3 = lngStop To UBound(Var1, 1)
    For lngCnt4 = 1 To UBound(Var1, 2)
        Var2(lngCnt3 - lngStop + 1, lngCnt4) = Var1(lngCnt3, lngCnt4)
    Next lngCnt4
Next lngCnt3
Sheet1.[a3444].Resize(UBound(Var2, 1), UBound(Var2, 2)).Value2 = Var2
End Sub

这篇关于可以将一定范围的变体转储到工作表中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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