Excel VBA 联合
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15388307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel VBA Union
提问by user1423997
In Excel 2010, how do I create a two column range from two separate ones using VBA?
在 Excel 2010 中,如何使用 VBA 从两个单独的范围创建两列范围?
The code below uses Union, but the combined range (rngAll) only contains the first column (rng1):
下面的代码使用 Union,但组合范围 (rngAll) 仅包含第一列 (rng1):
Dim rng1 As Range
Dim rng2 As Range
Dim rngAll As Range
Set rng1 = Range(TableColumn1)
Set rng2 = Range(TableColumn2)
Set rngAll = Application.Union(rng1, rng2)
Thanks.
谢谢。
回答by bonCodigo
Try this by qualifying the Range
object with Sheet
:
通过使用以下内容限定Range
对象来尝试此操作Sheet
:
Set rng1 = Sheets(1).Range(TableColumn1)
Set rng2 = Sheets(1).Range(TableColumn2)
Set rngAll = Application.Union(rng1, rng2)
Then in the Watch Window
or Immediate Window
, you may check the rngAll.Address
. It should show you both the ranges.
然后在Watch Window
or 中Immediate Window
,您可以检查rngAll.Address
. 它应该向您显示两个范围。