Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 不使用并集选择多个动态范围_Vba_Excel - Fatal编程技术网

Vba 不使用并集选择多个动态范围

Vba 不使用并集选择多个动态范围,vba,excel,Vba,Excel,我需要按照表格(“B1:D”和n+2)选择多个范围,每三列最多(“AI1:AK”和n+2),总共给出12个范围。我不想使用union,因为我需要在每个范围周围添加一个边框(而union会在所有范围的边缘周围添加一个边框),但我似乎无法选择所有范围 有没有一种方法可以在不使用union的情况下选择所有范围?您可以使用类似于范围(“A1:A2,C2:D4”)的多个范围 对于您的示例,请尝试以下操作: Sub PickMultipleAreas() Dim n As Long n = 2 With

我需要按照表格(“B1:D”和n+2)选择多个范围,每三列最多(“AI1:AK”和n+2),总共给出12个范围。我不想使用union,因为我需要在每个范围周围添加一个边框(而union会在所有范围的边缘周围添加一个边框),但我似乎无法选择所有范围


有没有一种方法可以在不使用union的情况下选择所有范围?

您可以使用类似于
范围(“A1:A2,C2:D4”)
的多个范围

对于您的示例,请尝试以下操作:

Sub PickMultipleAreas()
Dim n As Long

n = 2
With ActiveSheet
    .Range("B1:D" & n + 2 & "," & _
           "AI1:AK" & n + 2).BorderAround ColorIndex:=3, Weight:=xlThick
End With
End Sub

有关此概念和我编写的用于取消选择重叠范围的工具的更多信息,请参阅:

,以了解下一步的操作:

For i = 2 to 35 Step 3
    Range(Cells(1, i), Cells(n + 2, i + 2)).BorderAround 'your criteria here
Next i
或者使用
Offset()


两个测试都有效。

我已经接受了道格的答案,但这也很有效。谢谢你。@Moogle没问题。只是打字有点慢。我感谢你的支持!实际上,这是一个比我更好的方法。我是直截了当的,这更实际。
For i = 0 to 11
    Range("B1:D" & n + 2).Offset(0, i * 3).BorderAround 'your criteria here
Next i