Arrays VBA将所有范围变量添加到数组中

Arrays VBA将所有范围变量添加到数组中,arrays,vba,variables,range,Arrays,Vba,Variables,Range,我有一个VBA程序,我在一个选项卡上设置了150多个范围变量。我试图找出一种方法来清除与这些变量相关的所有范围的内容,到目前为止,我能想到的唯一方法是对每个变量逐个使用.ClearContents方法。例如: Sub rangeVariableQuestion() Dim personnel As Range Dim dateAndTime As Range Dim companyName As Range Dim reportDate As Range ''''''''''''''''''

我有一个VBA程序,我在一个选项卡上设置了150多个范围变量。我试图找出一种方法来清除与这些变量相关的所有范围的内容,到目前为止,我能想到的唯一方法是对每个变量逐个使用.ClearContents方法。例如:

Sub rangeVariableQuestion()

Dim personnel As Range
Dim dateAndTime As Range
Dim companyName As Range
Dim reportDate As Range

''''''''''''''''''' + 150+ more variables

Set personnel = Range("Personnel")
Set dateAndTime = Range("Date")
Set companyName = Range("Company")
Set reportDate = Range("reportdate")

'''''''''''''''

personnel.ClearContents
dateAndTime.ClearContents
companyName.ClearContents
reportDate.ClearContents

'''''''''''''''''''    

End Sub

是否有一种方法可以将过程中的所有变量转换为一个数组?这样我就可以循环使用每个变量来清除内容。

我可能会选择一个数组,我可以循环使用该数组,或者在150多个范围内使用一个数组

Sub rangeVariableQuestion()

    Dim personnel As Range
    Dim dateAndTime As Range
    Dim companyName As Range
    Dim reportDate As Range
    Dim nukeThese As Range

    ''''''''''''''''''' + 150+ more variables

    Set personnel = Range("Personnel")
    Set dateAndTime = Range("Date")
    Set companyName = Range("Company")
    Set nukeThese = Union(personnel, dateAndTime, companyName)   '<~~ start off by setting to the union of three
    Set reportDate = Range("reportdate")
    Set nukeThese = Union(nukeThese, reportDate)                 '<~~ continue by setting union to self and other(s)

    '''''''''''''''

    'clear the unioned range    
    nukeThese.ClearContents
    'or just clear the union directly
    Union(personnel, dateAndTime, companyName, reportDate).ClearContents

    '''''''''''''''''''

End Sub
Sub-rangeVariableQuestion()
将人员视为射程
Dim dateAndTime作为范围
Dim companyName As Range
Dim reportDate作为范围
暗淡的nukeThese As Range
150多个变量
设置人员=范围(“人员”)
设置日期和时间=范围(“日期”)
设置公司名称=范围(“公司”)

Set numethese=Union(personals,dateAndTime,companyName)“您是否考虑过包含150多个单独命名范围的“命名范围”?