将偏移行添加到给定范围. Excel VBA [英] Adding an Offset Row to a Given Range. Excel VBA

查看:80
本文介绍了将偏移行添加到给定范围. Excel VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量,开始时将其设置为给定范围.

I have a variable which at the beginning is set to a given range.

我想要一个循环语句,该语句将从给定范围的末尾开始向下一行并将其添加到该范围.

I want to have a loop statement that would take the next row down from the end of the given range and add it to that range.

即:

myRows = Range(1:10)

    For Each cell in myRows

       If cell.Value > 2048 Then

           myRows = myRows + myRows.Offset(1, 0) ---This is where i need help---

基本上,每次循环运行时,我如何自动增加范围.

Basically how do i auto increment the range each time the loop runs.

我还将如何添加到范围的前面.以及从范围的后面拿走.

Also how would I Add to the front of the range. As well as Take away from the back of the range.

范围(1:10)被隐藏 范围(11:20)隐藏了

Range(1:10) is unhidden Range(11:20) is hidden

我想在未隐藏范围内添加一个,该范围将从隐藏范围中删除,所以它是:

I want to add one to the unhidden range which would take away from the hidden range so its:

范围(1:11)未被隐藏 范围(12:20)隐藏了

Range(1:11) is unhidden Range(12:20) is hidden

推荐答案

您将myRows作为Variant数据类型.您需要将其声明为Range对象.

You have myRows as a Variant data type. You need to declare it as a Range object.

Dim myRows as Range

然后,您需要使用Set关键字来分配Range对象).

Then you would need to use the Set keyword to assign a Range object).

Set myRows = Range("1:10")

然后,使用范围.Resize方法:

Set myRows = myRows.Resize(myRows.Rows.Count+1, myRows.Columns.Count)

否则,如果您需要将myRows保持为Variant类型,请告知我,我可以对其进行重新处理.

Otherwise, if you need to maintain myRows as type Variant, let me know and I can re-work this.

这篇关于将偏移行添加到给定范围. Excel VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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