多个范围的VBA线

时间:2018-07-19 14:32:10

标签: excel vba range border line

我想要B1,E1和H1行有多个边框。如何扩展range命令而又不必一遍又一遍地重复呢?

代码是:

$(document).ready(function() {
    $(window).scroll(function() {
        if ($(document).scrollTop() > 20) {
            $('#masthead').addClass('sticky-border');

        }
        else {
            $('#masthead').removeClass('sticky-border');
        }
    });
});
`

2 个答案:

答案 0 :(得分:1)

您是说可以用Union实现吗?

Option Explicit
Public Sub test()
    Dim unionRng As Range
    With Worksheets("Table1")
    Set unionRng = Union(.Range("B1:B29"), .Range("E1:E29"), .Range("H1:H29"))
    End With
    unionRng.BorderAround _
        ColorIndex:=1
End Sub

您可以缩短为:

Public Sub test()
    With Worksheets("Table1")
       Union(.Range("B1:B29"), .Range("E1:E29"), .Range("H1:H29")).BorderAround _
        ColorIndex:=1
    End With
End Sub

答案 1 :(得分:0)

使用“相交”替代:

$