如何使用VBA命名多个范围?

时间:2018-06-19 17:33:51

标签: vba named-ranges

我在这个初学者问题上陷于困境。我想根据所附图片命名400个范围。名称为Range_1,Range_2等。错误是对当前区域的引用。

Ranges

Sub NameRange_Add()

    Dim RangeName As String
    Dim Reference As String
    Dim i As Integer

    For i = 1 To 2
        RangeName = "Range_" & i
        Reference = ActiveCell.CurrentRegion.Select
        Worksheets("Test").Names.Add Name:=RangeName, RefersTo:=Reference
        Selection.End(xlDown).Select
        Selection.End(xlDown).Select
    Next i

End Sub

0 个答案:

没有答案