|
'Application.Union 方法
'返回两个或多个区域的合并区域
'
Sub test()
Range("a1:b3,c5:d8").Select '文本地址引用方式
Union([a1:b3], [c5:d8]).Select '单元格区域引用方式
End Sub
'小结:虽然range也可以完成多区域的引用
'但文本地址的引用方式最多不能超过256个字符
'而union却没有这个限制
'我们经常利用变量与union进行单元格的连接
Sub 连接符单元格连接()
Dim rng As Range
For Each rngs In [b2:b10]
adss = rngs.Address
ads = ads & rngs.Address & ","
Next
ad = Left(ads, Len(ads) - 1)
End Sub
Sub union单元格连接()
Dim rng As Range, rngs As Range
Set rng = [b2]
For Each rngs In [b2:b10]
adss = rngs.Address
Set rng = Union(rng, rngs)
ads = rng.Address
Next
End Sub
|
|